Results 1 to 2 of 2
  1. #1
    frankycool is offline Member
    Join Date
    Nov 2009
    Posts
    4
    Rep Power
    0

    Default Arraylist Save and Load

    HI i am using this syntax to store arraylist to inventory.dat file.When i store, it give a scattered output on the .dat file like this.....

    sr Carsguimainexecution.SaleinfoEWf L productsalest Ljava/util/ArrayList;xpsr java.util.ArrayListxa I sizexp w
    sr Carsguimainexecution.SalesubZ㾝 xr Carsguimainexecution.SaleProducti>2q I CarnumberD pricesoldI
    productNumberD stockD unitsoldL Carbuyert Ljava/lang/String;L Carnameq ~ xp t Defaultq ~ sq ~  @I @@ @$ t dsdggsdrft fgsgsfsq ~  @@ @| @& t dfgdrht gyjgyjsq ~  @@ @p @( t dfsbt fddndfsq ~  @@ @È @$ t sdfsdft sdfsfsfsq ~  @$ @y @D t dsdgrght hdhdhsq ~  @$ @@ @Y t fbdfbt dfbdfbsq ~  @$ @Y @$ t defaultt defaultsq ~   t Defaultt Defaultx


    Is the output an error or its correct,and if its correct how can i load this information back to an arraylist.

    To Store,this is what i use excluding the try and catch:-

    Java Code:
    File f = new File( "C:\\data\\inventory.dat" );
    FileOutputStream out = new FileOutputStream( f );
    ObjectOutputStream objectOut = new ObjectOutputStream( out );
    objectOut.writeObject( inv );

    This is a sample of how my arraylist looks like;

    Java Code:
    products.add( new CarsSubProduct( "FordMustang",1,1000,10000 ) );
    Please any advice will be really helpful.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by frankycool View Post
    HI i am using this syntax to store arraylist to inventory.dat file.When i store, it give a scattered output on the .dat file like this..... [ binary gibberish removed ... ]
    Is the output an error or its correct,and if its correct how can i load this information back to an arraylist.

    To Store,this is what i use excluding the try and catch:-

    Java Code:
    File f = new File( "C:\\data\\inventory.dat" );
    FileOutputStream out = new FileOutputStream( f );
    ObjectOutputStream objectOut = new ObjectOutputStream( out );
    objectOut.writeObject( inv );

    This is a sample of how my arraylist looks like;

    Java Code:
    products.add( new CarsSubProduct( "FordMustang",1,1000,10000 ) );
    Please any advice will be really helpful.
    The output is correct as far as I can tell. ObjectOutputStreams don't write text data (i.e. human readable data). What you saw is the serialized form of your ArrayList; you know how to use those output streams so I'm sure you know how to use those input streams. Try it and see if you get your ArrayList back. If you didn't get an Exception when writing your CarsSubProducts must've implemented the Serializable interface.

    kind regards,

    Jos

Similar Threads

  1. How can i save the data Internally(auto save)
    By Rama Koti Reddy in forum AWT / Swing
    Replies: 2
    Last Post: 11-01-2010, 09:31 PM
  2. save will work but load wont?!?!
    By Sticks_ll in forum New To Java
    Replies: 1
    Last Post: 06-12-2008, 05:19 AM
  3. Replies: 2
    Last Post: 04-21-2008, 12:43 PM
  4. How to Save/Load Vector to/from file
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 09:37 PM
  5. Help with load image
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 08:16 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •