mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-13 10:15:44 +00:00
Merge pull request #788 from diffblue-assistant/finallyclosetotrywithresources
Use try-with-resources
This commit is contained in:
1 file changed
+1
-4
@@ -37,11 +37,8 @@ public class SimpleFileWriter {
|
|||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public SimpleFileWriter(String filename, FileWriterAction action) throws IOException {
|
public SimpleFileWriter(String filename, FileWriterAction action) throws IOException {
|
||||||
FileWriter writer = new FileWriter(filename);
|
try (FileWriter writer = new FileWriter(filename)) {
|
||||||
try {
|
|
||||||
action.writeFile(writer);
|
action.writeFile(writer);
|
||||||
} finally {
|
|
||||||
writer.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user