import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; public class Writer { static ArrayList persons = new ArrayList(); public static void main(String[] args) { persons.add(new Person("Jacob", 43)); persons.add(new Person("Denise", 19)); writeToFile("example.txt"); } public static void writeToFile(String fileName) { try { FileWriter fw = new FileWriter(fileName); fw.write("Title of the written lines\r\n"); for (int i = 0; i < persons.size(); i++) { persons.get(i).write(fw); fw.write("\r\n"); } fw.close(); } catch (IOException e) { e.printStackTrace(); } } }