How to check EOF condition
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Binu_Mathew
Posted On:   Saturday, August 10, 2002 09:47 AM

Hi All,

I am reading a vector written to a file using ObjectInputStream. Please see the code below

1.FileInputStream istream = new FileInputStream(File);
2.ObjectInputStrea ostream = new ObjectInputStream(istream);
3.Vector v = (Vector) ostream.readObject();

When the file is empty the above code throws (at the third line above) EOFException.

How can i check for EOF condition here? Please help me in solving the issue.

Thanks in advance.
Binu Mathew.

Re: How to check EOF condition

Posted By:   eimi_nos  
Posted On:   Saturday, August 10, 2002 06:17 PM

How about this.

try{ //
}catch(EOFException e){
System.out.println("File is possibly empty.");
// or
// throw new Exception("File is possibly empty.");
// with getMessage() method for the caught Exception.
}


Byte length is known if you use "another" FileInputStream object (e.g., _istream) and the read() method, with counting block

(while(_istream.read()!=-1){counter++;}).

About | Sitemap | Contact