提交 f36de036 编写于 作者: D Diffblue assistant

Use try-with-resources

Replace try statements that close a resource in the finally block with a
try-with-resources statement [1].

This commit was created automatically by Diffblue refactorings (https://www.diffblue.com/).

[1] https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
上级 b6426230
......@@ -37,11 +37,8 @@ public class SimpleFileWriter {
* Constructor
*/
public SimpleFileWriter(String filename, FileWriterAction action) throws IOException {
FileWriter writer = new FileWriter(filename);
try {
try (FileWriter writer = new FileWriter(filename)) {
action.writeFile(writer);
} finally {
writer.close();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册