Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem obtaining last record of a Binary File  RSS feed

 
Denise Advincula
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
Thank you very much for the replies to my inquiries.

This is in connection to my previous posts here and here.

I am now successful on obtaining the correct data from a Binary file using RandomAccessFile. However, I could not seem to understand why I couldn't get the last record (or imaginary row) of my binary file.

My program just reads data from an Excel then writes/appends each field to a Binary File. On writing to the Binary file, I use DataOutputStream. Then on reading, I use RandomAccessFile as abovementioned. My excel has 100 records. Theoretically, I should expect 100 records as well, written in the binary file. But my program prints 99 records only. I checked the sizes after writing using DataOutputStream's size() and before reading using RandomAccessFile's length() and they're the same.

Here's my loop on reading the binary file:



I hope you could point to me if there's something wrong with my approach, I would really appreciate it.
Thanks in advance!>
 
rk palleru
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.Here retrieving values "i<size" , It retrieves length-1 then we could not get last file. so use "i<=size" in for loop.

2. In if(i%99==0) means if i value is 99 ,then (99%99==0) next time (100%99==0) in this case if condition does not satisfy









 
Denise Advincula
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rk palleru wrote:1.Here retrieving values "i<size" , It retrieves length-1 then we could not get last file. so use "i<=size" in for loop.

2. In if(i%99==0) means if i value is 99 ,then (99%99==0) next time (100%99==0) in this case if condition does not satisfy



You are actually correct. I overlooked my logic.
Thanks very much for the suggestion.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!