浏览代码

写文件操作改为 try with resource 形式

James 4 年之前
父节点
当前提交
9137f6fdb9
共有 1 个文件被更改,包括 1 次插入8 次删除
  1. 1 8
      src/main/java/com/jfinal/plugin/activerecord/generator/DataDictionaryGenerator.java

+ 1 - 8
src/main/java/com/jfinal/plugin/activerecord/generator/DataDictionaryGenerator.java

@@ -230,18 +230,11 @@ public class DataDictionaryGenerator {
 		}
 		
 		String target = dataDictionaryOutputDir + File.separator + dataDictionaryFileName;
-		OutputStreamWriter osw = null;
-		try {
-			osw = new OutputStreamWriter(new FileOutputStream(target), "UTF-8");
+		try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(target), "UTF-8")) {
 			osw.write(ret);
 		}
 		catch (IOException e) {
 			throw new RuntimeException(e);
 		}
-		finally {
-			if (osw != null) {
-				try {osw.close();} catch (IOException e) {LogKit.error(e.getMessage(), e);}
-			}
-		}
 	}
 }