Help coderanch get a
new server
by contributing to the fundraiser
  • 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

RandomAccessFile(urgent)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have opened a File, FileOutputStream for writing a file. Can I open a RandomAccessFile om the previously mentioned File and use the getFilePointer() method to read the current offset in the file r_asthana@hotmail.com
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
It depends on what exactly you are trying to do!
If you simply wants to read contents of a file, you can use RandomAccessFile no need to use any other classes along with this.
You can read any data type with this class. It has wide range of read methods.
HtH
SivaPrasad
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ratin- no, not the way you describe. First, some OS's may not even let you open a new RandomAccessFile on a file that you're already writing to with another stream. Second, writing with the OutputStream has no effect on the offset of the RandomAccessFile. The two objects are independant. The simplest solution is to use only RandomAccessFile as Siva suggests. Alternately you can keep track of how many bytes have been written to the OutputStream; I once wrote an extension of FilterOutputStream for this purpose. (You have to make sure no bytes are buffered in other intermediate streams when you query this class for the current offset.)
 
Dinner will be steamed monkey heads with a side of tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic