I have created an arraylist that is made up of custom objects. Basically the user will create a class and every time a class is created, a new Lecture (my custom object) is
I use a class in a Weather app I'm developing...
public class RegionList extends ArrayList {} // Region implements Serializeable
To save I use code like this...
FileOutputStream outStream = new FileOutputStream(Weather.WeatherDir + "/RegionList.dat");
ObjectOutputStream objectOutStream = new ObjectOutputStream(outStream);
objectOutStream.writeInt(uk_weather_regions.size()); // Save size first
for(Region r:uk_weather_regions)
objectOutStream.writeObject(r);
objectOutStream.close();
NOTE: Before I write the Region objects, I write an int to save the 'size' of the list.
When I read back I do this...
FileInputStream inStream = new FileInputStream(f);
ObjectInputStream objectInStream = new ObjectInputStream(inStream);
int count = objectInStream.readInt(); // Get the number of regions
RegionList rl = new RegionList();
for (int c=0; c < count; c++)
rl.add((Region) objectInStream.readObject());
objectInStream.close();