• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RandomAccessFile(urgent)

 
ratin asthana
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Siva Prasad
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • 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
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic