使用 ArrayList 中的值创建新文本文件的最简单方法是什么?

What is the simplest way to create a new text file with values from an ArrayList?

我目前正在寻找一种方法来创建一个新的文本文件,该文件是使用 ArrayList 中的值创建的。如何创建一个文本文件,使我能够拥有我正在寻找的格式?

public static void createTextFileFromArrayList() {

    List<String> cities = new ArrayList<String>();
    cities.addAll(Arrays.asList("Boston", "Washington", "Irving", "Dallas"));

    //Get the file reference
    Path path = Paths.get("C:\apps\output.txt");

    //Use try-with-resource to get auto-closeable writer instance
    try (BufferedWriter writer = Files.newBufferedWriter(path)) {
        cities.forEach(city -> {
            try {
                writer.write(city);
                writer.write("\n");
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
    }
}