Commit 3969cd4b authored by Tuukka Lehtonen's avatar Tuukka Lehtonen

Always close written file explicitly in StringIO.{writeLines,appendLine}

gitlab #675
parent 8ce34898
......@@ -38,20 +38,20 @@ public class StringIO {
}
public static void writeLines(String fileName, List<String> lines) throws IOException {
BufferedWriter writer = Files.newBufferedWriter(Paths.get(fileName), UTF8);
for(String line : lines) {
writer.write(line);
writer.write("\n");
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(fileName), UTF8)) {
for(String line : lines) {
writer.write(line);
writer.write("\n");
}
}
writer.close();
}
public static void appendLine(String fileName, String line) throws IOException {
BufferedWriter writer = Files.newBufferedWriter(Paths.get(fileName), UTF8,
StandardOpenOption.CREATE, StandardOpenOption.APPEND);
writer.write(line);
writer.write("\n");
writer.close();
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(fileName), UTF8,
StandardOpenOption.CREATE, StandardOpenOption.APPEND)) {
writer.write(line);
writer.write("\n");
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment