All pastes #2070365 Raw Edit

Unnamed

public text v1 · immutable
#2070365 ·published 2011-05-27 13:57 UTC
rendered paste body
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;


public class Writer {
	static ArrayList<Person> persons = new ArrayList<Person>();
	
	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(); }
	}
}