Use Files.write for a concise way to write to files, automatically handling resource management.
Source Code
List lines = Arrays.asList("The first line", "The second line");
Path file = Paths.get("output.txt");
try {
Files.write(file, lines, Charset.forName("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
}