Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > writeObject with ArrayList of ArrayList?

Reply
Thread Tools

writeObject with ArrayList of ArrayList?

 
 
Kaidi
Guest
Posts: n/a
 
      01-01-2004
Hi,
I am thinking of using this code to output and readin the data:

------------
File thefile = new File(outfile);
FileOutputStream fout = new FileOutputStream(thefile);
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(vectorDB);
oos.close();
fout.close();
----------
the "vectorDB" is a ArrayList, with each element (item) of it another ArrayList.

Anyone can confirm that usign the above code, will it be properly saved to
file? (in another word, does writeObject can handle nested objects?)

Thanks a lot.
 
Reply With Quote
 
 
 
 
Lee Fesperman
Guest
Posts: n/a
 
      01-01-2004
Kaidi wrote:
>
> Hi,
> I am thinking of using this code to output and readin the data:
> ------------
> File thefile = new File(outfile);
> FileOutputStream fout = new FileOutputStream(thefile);
> ObjectOutputStream oos = new ObjectOutputStream(fout);
> oos.writeObject(vectorDB);
> oos.close();
> fout.close();
> ----------
> the "vectorDB" is a ArrayList, with each element (item) of it another ArrayList.
>
> Anyone can confirm that usign the above code, will it be properly saved to
> file? (in another word, does writeObject can handle nested objects?)


Yes, writeObject() can handle nested objects (as long as all objects implement
Serializable). Your code will work.

--
Lee Fesperman, FirstSQL, Inc. (http://www.firstsql.com)
================================================== ============
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
 
Reply With Quote
 
 
 
 
hiwa
Guest
Posts: n/a
 
      01-01-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Kaidi) wrote in message news:<(E-Mail Removed). com>...
> Hi,
> I am thinking of using this code to output and readin the data:
>
> ------------
> File thefile = new File(outfile);
> FileOutputStream fout = new FileOutputStream(thefile);
> ObjectOutputStream oos = new ObjectOutputStream(fout);
> oos.writeObject(vectorDB);
> oos.close();
> fout.close();
> ----------
> the "vectorDB" is a ArrayList, with each element (item) of it another ArrayList.
>
> Anyone can confirm that usign the above code, will it be properly saved to
> file? (in another word, does writeObject can handle nested objects?)
>
> Thanks a lot.


Try youself and report the result on the forum.
Try XMLEncoder/Decoder instead of ObjectOutput/InputStream.
Or, throw away raw Java object and use ordinary DB.
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      01-01-2004
"Kaidi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi,
> I am thinking of using this code to output and readin the data:

<snip 'snippet'>

Java object serialisation is quite magical,
serialize a vetor of your custom object,
containing many to many links between
the objects, and you'll find they deserialize
into the same structure.

Great stuff. Try it.

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site


 
Reply With Quote
 
Kaidi
Guest
Posts: n/a
 
      01-03-2004
Thanks all.
I tried and it seems it working on nested object.

(E-Mail Removed) (Kaidi) wrote in message news:<(E-Mail Removed). com>...
> Hi,
> I am thinking of using this code to output and readin the data:
>
> ------------
> File thefile = new File(outfile);
> FileOutputStream fout = new FileOutputStream(thefile);
> ObjectOutputStream oos = new ObjectOutputStream(fout);
> oos.writeObject(vectorDB);
> oos.close();
> fout.close();
> ----------
> the "vectorDB" is a ArrayList, with each element (item) of it another ArrayList.
>
> Anyone can confirm that usign the above code, will it be properly saved to
> file? (in another word, does writeObject can handle nested objects?)
>
> Thanks a lot.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
writeObject signature Roedy Green Java 35 04-15-2006 04:10 AM
writeObject and readObject problem juicy Java 28 09-25-2004 02:43 PM
Overriding existing Serializeable writeObject ? jprogrammer Java 10 04-22-2004 10:34 PM
Socket / writeObject / NotSerializableException question JMC Java 1 04-07-2004 01:30 PM
writeObject too slow for big object, any idea? Kaidi Java 7 01-06-2004 11:32 AM



Advertisments