Reputation: 77
I've tried to get my head around this, but can't so asking the forum. Does anyone think it would be possible to save multiple ArrayLists to a file? Would I have to create multiple files for each List or could I bung them all in one with a reference of some sort? So far I have knocked up a quick experiment but to no avail. (this is just a quick representation of my code but I am away from the computer)
try {
fos = new FileOutputStream(file);
oos = new ObjectOutputStream(fos);
oos.writeObject(Ing);
oos.writeObject(IngN);
oos.writeObject(Step);
oos.close();
fos.close();
}
etc
Upvotes: 0
Views: 228
Reputation: 6928
You would be best to serialize the arraylists to something like json first, and then write that to a file.
You could create a simple class that holds 2 arraylists, and then serialize that class so you end up with one string that contains both arraylists, which you can write to one file.
For serializing to json, check out jackson mapper.
I'm not sure what your use case is, but you may want to also look into saving the data into a database instead of a file.
Upvotes: 1