Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

RandomAccessFile(urgent)  RSS feed

 
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
 
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
 
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.)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!