Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Arraylist Save and Load

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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:-

    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;

    products.add( new CarsSubProduct( "FordMustang",1,1000,10000 ) );

    Please any advice will be really helpful.


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Arraylist Save and Load

    That looks alright, Java just serialises it all into the file.

    How about using an ObjectInputStream to read it back?

    See Create ObjectInputStream from FileInputStream : ObjectInputStreamFileJava Tutorial

    // Json

  3. The Following User Says Thank You to Json For This Useful Post:

    frankycool (November 14th, 2009)

Similar Threads

  1. How to use an ArrayList and what is its advantage over array?
    By JavaPF in forum Java SE API Tutorials
    Replies: 4
    Last Post: December 21st, 2011, 04:44 AM
  2. how to load a class and type cast to that class?
    By chinni in forum Object Oriented Programming
    Replies: 2
    Last Post: November 9th, 2009, 10:18 AM
  3. [SOLVED] Extracting an How to ArrayList from an ArrayList and convert to int??
    By igniteflow in forum Collections and Generics
    Replies: 2
    Last Post: August 16th, 2009, 01:11 PM
  4. Replies: 1
    Last Post: April 20th, 2009, 11:17 AM
  5. Saving .jsp page as .pdf file while generating report for struts based web application
    By ravindra_kumar_tiwari in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: August 12th, 2008, 09:32 AM

Tags for this Thread