What is the correct way of specifying the end of a file when using RandomAccessFile class?
or
I found conflicting information from two sources. That is why I want to confirm. Thanks
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
length returns the length of the file measured in bytes, i.e. if length returns 10 it means that your file is ten bytes long from byte 0 to byte 9. If you positioned (seek) the file pointer with the value returned by length, you will have your pointer just after the last byte. The file looks like this: ------------------------------------- | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ------------------------------------- oraf.seek(oraf.length()) (i.e. oraf.seek(10)) will result in setting the file pointer at position 10. If you want to point to the last byte in the file then you have to use the length()-1 offset. In that case the pointer points to byte 9. HIH
------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform [This message has been edited by Valentin Crettaz (edited December 02, 2001).]