wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes end of file check not coming right Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "end of file check not coming right" Watch "end of file check not coming right" New topic
Author

end of file check not coming right

Nina Binde
Ranch Hand

Joined: Sep 24, 2004
Posts: 85
Hi everyone,

I am trying to check for the end of file like this in the for loop:
for (long locationInFile = dbHeader.getOffset();
locationInFile < database.length();
locationInFile += dbHeader.getRecordLength(){
......
}

For reason unknown to me, the database.length returns 5258. The length of the file in the hex editor is 5222 which is what I had calculated manually too with the number of records known. Hence, I keep getting the IOException in the above code.
Anyone have ideas as to why the database.length gives me 5258 instead of 5222 ? Thanks for your replies.
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
just a guess, try
Gabriel Vargas
Ranch Hand

Joined: May 16, 2007
Posts: 145
Hi Nina,

You can post the code, it is difficut with this segment told anything.


Gabriel Vargas
SCJP, SCJD, now studying for SCWCD and working to be a better person
Nina Binde
Ranch Hand

Joined: Sep 24, 2004
Posts: 85
ok. the code is as follows:


I am trying to read the total number of records in the above code. I check the end of file by database.length.
Here database is an instance of RandomAccessFile. dbHeader is a static instance of the database header class. recordCount is an Integer variable to return the count of total records.

The problem I am facing is that every time I run this code, it gives me an EOFException. The reason is database.length returns a value of 5258. I am expecting it to return 5222 since the hex editor shows me 5222. I also verified with the total number of records which again comes to 5222.
Why would database.length return 5258 instead of 5222?

Thanks guys...
Gabriel Vargas
Ranch Hand

Joined: May 16, 2007
Posts: 145
It seems to be ok, i think than your throuble can be reading header or reading contractors from a bad position or bad length. I see you use log (only to track if recNo increments ), but you can use this log to debug what is happen, logging each contractor than you read and compares it with your hex editor view, i do the same when i'm debugging my data class.

Tell us if it works. I hope it helps you.
Nina Binde
Ranch Hand

Joined: Sep 24, 2004
Posts: 85
Hi Gabriel,

Really appreciate your help. I finally got it working..had a tough time debugging. It was pretty silly actually, had the same file in different directories. While I was looking at the file in one directory, it was actually reading from another directory. That file was corrupted by something I had already written before. Hence it was showing the length different than what I expected. Phew....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: end of file check not coming right
 
Similar Threads
B & S read method
EOF Exception while inserting record through threading
B & S read method of interface
RecordNotFoundException
Problems with EOFException