Skip to content

Commit

Permalink
Close writer properly
Browse files Browse the repository at this point in the history
  • Loading branch information
wggihan committed Jun 6, 2017
1 parent b28c08b commit 2b28125
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

Expand All @@ -30,10 +30,9 @@
public class Utils {

public static void writeToBalFile(String filePath, String content) throws IOException {
Charset charset = Charset.forName("UTF-8");
BufferedWriter writer = Files.newBufferedWriter(Paths.get(filePath), charset);
writer.write(content);
writer.flush();
writer.close();
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(filePath), StandardCharsets.UTF_8)) {
writer.write(content);
writer.flush();
}
}
}

0 comments on commit 2b28125

Please sign in to comment.