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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
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.