Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Handling EOF while using ObjectInputStream

807589Nov 7 2008 — edited Nov 8 2008
How to know whether we have reached eof while using ObjectInputStream to read a bunch of objects stored in a file.

i have a file named india.txt which contains three objects(Junk) stored using ObjectOutputStream, Now i am reading those objects using the following code snippet
 
objectIn = new ObjectInputStream(new BufferedInputStream(
		    fin = new FileInputStream("c:/Files/india.txt")));

	    while (true) {  // this is not correct. how to check whether we reached end of file
		object = (Junk) objectIn.readObject();  //may throw EOFException if the file pointer is beyond EOF
	    }
Thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 6 2008
Added on Nov 7 2008
5 comments
776 views