1551
Use:
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("myFile.txt"), StandardCharsets.UTF_8))) {
writer.write("text to write");
}
catch (IOException ex) {
// Handle me
}
Using try() will close stream automatically. This version is short, fast (buffered) and enables choosing encoding.
This feature was introduced in Java 7.