Saturday, 31 August 2013

JAVA writing and loading an Object ArrayList

JAVA writing and loading an Object ArrayList

I'm working on a program about students (saving the name, age and other
information into objects and storing those objects into an arrayList). So
far so good, I even got the JFrames to work exactly how I want them but
the problem shows up when I try to write all that information in a text
file.
How can I do that?
I tried the FileOutputStream with the ObjectOutputStream but I'm most
likely not doing it right since I keep getting an IOException.
An example of a program storing an arrayList with 2 or more Objects
containing 2 or more variables each is pretty much what I'm looking for.
I've seen a couple of times on different websites people suggesting to do
(but it gives me an IOException)
FileOutputStream fos=new FileOutputStream("FileName.txt");
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(myObjectArrayList);

No comments:

Post a Comment