EDIT: I solved the problem, I forgot to close the ObjectOutputStream. 'doh! I'll leave the question just in case someone wants to propose a more elegant option, which would be much appreciated.
I currently am trying to write a class called phonebook to file, which contains an ArrayList of objects called PhonebookEntry. Here is the Phonebook class:
import java.util.ArrayList;
import java.io.*;
public class Phonebook implements Serializable
private static final long serialVersionUID = 1;
ArrayList<PhonebookEntry> phonebookEntries = new ArrayList<PhonebookEntry>();
public void addEntry(String name, String number) {
PhonebookEntry newEntry = new PhonebookEntry(name, number);
phonebookEntries.add(newEntry);
}
}
I have tried using a simple ObjectInput/OutputStream and I can get it to save that way, but not to load (usually with an EOFExcpetion). Is there an elegant way to save an object like this, or is there any way to save an ArrayList of objects to a file?