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.SaleinfoÕE£ñWfö L productsalest Ljava/util/ArrayList;xpsr java.util.ArrayListxÒ™Ça I sizexp w
sr Carsguimainexecution.SalesubZã¾ÓÅ xr Carsguimainexecution.SaleProductøié>‘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.

7 Years
Discussion Span
Last Post by javaAddict

Because you are saving the object as binary data not as text. You are serializing. You cannot open the file and view it. If you want to read it then use the opposite way.


If you want to save it as text then use BufferedWriter, but it needs much more work. With your way, you did it in 3-4 lines.

I hope that your class implements the java.io.Serializable interface.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.