File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes error while reading objects from file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "error while reading objects from file" Watch "error while reading objects from file" New topic
Author

error while reading objects from file

sakshi saw
Greenhorn

Joined: Jun 06, 2009
Posts: 6
Below is a short code to explain the problem i am facing
i have been working on the same for past one week i am facing exceptions while reading a file containing more than one objects



would be very grateful for early reply!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8707
    
    6

If you are getting an exception, it is a good idea to share it with us. How are we to know what your code is doing?
I anticipate you are getting an OptionalDataException. If you look at the Java Documentation for ObjectInputStream:
Any attempt to read object data which exceeds the boundaries of the custom data written by the corresponding writeObject method will cause an OptionalDataException to be thrown with an eof field value of true.

Many people find that relying on an exception to signal an expected condition like EOF is counter-intuitive. The most common work-around is to either write the number of objects to the file then read only that number of times, or to put the objects in a collection and do a single read to load the collection and all the serialized objects (I prefer the latter).


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error while reading objects from file
 
Similar Threads
object gets serialized, be on heap?
Jtable loading after being saved problem
iText: Digital signature
Problem with passing object from servlet to applet using jsp page
static, transient and volatile variables in Serialization