ソースを参照

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

James 4 年 前
コミット
9137f6fdb9

+ 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);}
-			}
-		}
 	}
 }