This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
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
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Reply 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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: NX: What RandomAccessFile mode to use?
 
Similar Threads
IO streams
How to write to a particular location in a file?
Problem with ArrayList !!!!!
using a RandomAccessFile
Read only specified number of rows from a .csv file