• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

end of file check not coming right

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just a guess, try
 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
reply
    Bookmark Topic Watch Topic
  • New Topic