*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: I have some question about EOFException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S: I have some question about EOFException" Watch "B&S: I have some question about EOFException" New topic
Author

B&S: I have some question about EOFException

Jiwoong Lee
Greenhorn

Joined: Oct 06, 2004
Posts: 5
Hi All.

I am working with B&S.
but I have a question about database.
when i read db-2x2.db file using RandomAccessFile. I am not sure how to handle EOFException. Just use catch clause and throw some message ?
or something else ?

thanks for your reply
Matt Sheehan.
Ranch Hand

Joined: Oct 08, 2004
Posts: 63
I don't think this exception should ever be thrown. When counting the records, you should make sure not to read past the end of the file by using file.getFilePointer() and file.length(). After you know the number of records, there will be no need to read past the end of the file. If you take these precautions and still get an EOFException, then you know something crazy is going on and you should maybe think about closing the app(after notifying the user). In my case, I throw a FatalException if an IOException is caught here(which also catches EOF) because all IOExceptions are bad news.

Matt
Inuka Vincit
Ranch Hand

Joined: Aug 10, 2004
Posts: 175
Matt is right. I also found out that when I open the file with the "rw" option, the file pointer keeps on going even after the end of the file. So either way its not a good way to detect the end of the file.


MCP (C# application dev 70-316) 860<br />SCJP 1.4 100% SCJD (URLyBird) 378<br />MAD 100% nuts
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S: I have some question about EOFException
 
Similar Threads
NX: Using InputStreamReader together with DataInputStream
Circle in DB
Opinions On Reading Data File
Finally
Synchronization of public methods in DVDDatabase