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!>
SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCPJBCD in progress
rk palleru
Greenhorn
Joined: Feb 26, 2009
Posts: 22
posted
0
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
Joined: Jan 01, 2007
Posts: 153
posted
0
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.
This message was edited 1 time. Last update was at by Denise Advincula
subject: Problem obtaining last record of a Binary File