From f36de036f68a43aafe2bbd760890ae412a602fc2 Mon Sep 17 00:00:00 2001 From: Diffblue assistant Date: Thu, 23 Aug 2018 11:28:17 +0100 Subject: [PATCH] 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 --- .../java/com/iluwatar/execute/around/SimpleFileWriter.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/execute-around/src/main/java/com/iluwatar/execute/around/SimpleFileWriter.java b/execute-around/src/main/java/com/iluwatar/execute/around/SimpleFileWriter.java index 3c98597cb..559e70270 100644 --- a/execute-around/src/main/java/com/iluwatar/execute/around/SimpleFileWriter.java +++ b/execute-around/src/main/java/com/iluwatar/execute/around/SimpleFileWriter.java @@ -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(); } } }