aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: What RandomAccessFile mode to use? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: What RandomAccessFile mode to use?" Watch "NX: What RandomAccessFile mode to use?" New topic
Author

NX: What RandomAccessFile mode to use?

Jacques Bosch
Ranch Hand

Joined: Dec 18, 2003
Posts: 319
Should I open my RandomAccessFile in "rw" or "rws" or "rwd"?


Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
RW is suffice.
Jacques Bosch
Ranch Hand

Joined: Dec 18, 2003
Posts: 319
OK, Thanx.
Nick Shrine
Greenhorn

Joined: Jul 17, 2003
Posts: 11
Why?


Nick<br />SCJP<br />SCJD
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Hi Nick,
I went with "rw".
From the Java API:
"rw": Open for reading and writing. If the file does not already exist then an attempt will be made to create it.
"rws": Open for reading and writing, as with "rw", and also require that every update to the file's content or metadata be written synchronously to the underlying storage device.
"rwd": Open for reading and writing, as with "rw", and also require that every update to the file's content be written synchronously to the underlying storage device.
The "rws" and "rwd" modes work much like the force(boolean) method of the FileChannel class, passing arguments of true and false, respectively, except that they always apply to every I/O operation and are therefore often more efficient. If the file resides on a local storage device then when an invocation of a method of this class returns it is guaranteed that all changes made to the file by that invocation will have been written to that device. This is useful for ensuring that critical information is not lost in the event of a system crash. If the file does not reside on a local device then no such guarantee is made.
The "rwd" mode can be used to reduce the number of I/O operations performed. Using "rwd" only requires updates to the file's content to be written to storage; using "rws" requires updates to both the file's content and its metadata to be written, which generally requires at least one more low-level I/O operation.

After reading the above quotation from the Java API, I was unable to see how "rws" or "rwd" did anything useful for me. Now, that's probably because I don't really understand what problem is being solved here. I experienced no problems with "rw" mode, so I couldn't justify the overhead of using "rws" or "rwd", especially because I didn't understand how they helped me.
Hope this helps,
George


Regards, George
SCJP, SCJD, SCWCD, SCBCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: What RandomAccessFile mode to use?