aspose file tools
The moose likes Java in General and the fly likes Writing and Reading Serialized objects Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Writing and Reading Serialized objects" Watch "Writing and Reading Serialized objects" New topic
Author

Writing and Reading Serialized objects

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 224
I am writing serialized objects as follows



And i am reading the object as follows

The above reading code assumes that there is only one object in the file if there were more than one object written to the file from the list what should the reading code look like. How could i determine the total no of ojects in a file and read each one consecutively ???
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2329
You can either write the number of objects as an integer to the file before all the objects, or you can keep reading objects until the input stream is exhausted, or you could just serialize the array list to the file instead of its member objects.
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 224
Tim Moores wrote:You can either write the number of objects as an integer to the file before all the objects, or you can keep reading objects until the input stream is exhausted, or you could just serialize the array list to the file instead of its member objects.


How could i serialize the arraylist ?? I thought object were suppose to implement the serializable interface it they had to be serialized
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2329
Is it a java.util.ArrayList you're using? That implements Serializable.
 
 
subject: Writing and Reading Serialized objects
 
Threads others viewed
Applet and Struts
Send a whole file across
Object Read problem
File into object stream
Serialization Problem

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture