Pro JavaExpert level Java questions not about a specific book. Please indicate your version.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Pro Java section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
How to deserialize all the objects stored in a file.?
I am storing random number of objects into a file using ObjectOutputStream and is working file n i also know that using readObjectof ObjectInputStream we can read the object. But the thing is (1)how will i know how many objects are there in the file?
(2)how to read all the objects which are instances of the same class from the file?
Read an object from the file assign it to an Object class variable and use the getClass() method to get the class name, and compare it with required class name if equal continue your process, else continue reading another object.
I think, you should have all the objects present and it can be object hierarchy as well, and now while deserializing, it will construct the
entire object graph.
There are some questions and answers to serialization and deserialization, I came across