Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

end of file check not coming right

 
Nina Binde
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just a guess, try
 
Gabriel Vargas
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nina,

You can post the code, it is difficut with this segment told anything.
 
Nina Binde
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic