writeObject with ArrayList of ArrayList?

Discussion in 'Java' started by Kaidi, Jan 1, 2004.

  1. Kaidi

    Kaidi Guest

    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. :)
    Kaidi, Jan 1, 2004
    #1
    1. Advertising

  2. 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)
    Lee Fesperman, Jan 1, 2004
    #2
    1. Advertising

  3. Kaidi

    hiwa Guest

    (Kaidi) wrote in message news:<>...
    > 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.
    hiwa, Jan 1, 2004
    #3
  4. "Kaidi" <> wrote in message
    news:...
    > 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
    Andrew Thompson, Jan 1, 2004
    #4
  5. Kaidi

    Kaidi Guest

    Thanks all.
    I tried and it seems it working on nested object.

    (Kaidi) wrote in message news:<>...
    > 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. :)
    Kaidi, Jan 3, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kaidi
    Replies:
    7
    Views:
    4,394
    Robert Olofsson
    Jan 6, 2004
  2. JMC
    Replies:
    1
    Views:
    776
    Roedy Green
    Apr 7, 2004
  3. jprogrammer
    Replies:
    10
    Views:
    5,031
    Tony Morris
    Apr 22, 2004
  4. Roedy Green

    writeObject signature

    Roedy Green, Jun 8, 2004, in forum: Java
    Replies:
    35
    Views:
    1,270
    Dale King
    Apr 15, 2006
  5. juicy
    Replies:
    28
    Views:
    2,253
    Andrew Thompson
    Sep 25, 2004
Loading...

Share This Page