Home arrow static arrow Java Programming [Archive] - ObjectInputStream EOF
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - ObjectInputStream EOF
This topic has 1 reply on 1 page.

Registered: 10/4/03
ObjectInputStream EOF  
Jun 16, 2004 2:44 PM

Hey Guys, how do you prevent an EOF exception when using readObject() in an ObjectInputStream?
Basically I'm asking what to do if readObject() is called on an EMPTY file and/or if the file isn't empty how to readObject() until EOF is reached...

I know in other streams you could say
if(in.read() != -1)temp = in.read()

But readObject() doesn't seem to return -1 like read() does. I guess I can just catch the EOFException but isn't there a way to prevent it from being thrown to begin with?

Registered: 1/24/02
Re: ObjectInputStream EOF  
Jun 16, 2004 7:10 PM (reply 1 of 1)

This exception (EOFException) is mainly used by data input streams to signal end of stream. You can process it as a signal of reaching the end of the stream.
This topic has 1 reply on 1 page.