• 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

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
reply
    Bookmark Topic Watch Topic
  • New Topic