Forums Register Login

Problem obtaining last record of a Binary File

+Pie Number of slices to send: Send
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!>
+Pie Number of slices to send: Send
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









+Pie Number of slices to send: Send
 

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.
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1006 times.
Similar Threads
Read and Write doubts
Java Beginner's I/O Question
Restart in a RandomAccessFile
Seek Method for files(Urgent)
Returning the last line in a file.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:29:27.