Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: RandomAccessFile Mode "rws" vs "rwd"?

The RandomAccessFile constructor accepts a mode string specifying how a file should be open.

I'm confused about the difference between "rws" and "rwd" modes.

Here's what the docs state:

"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 "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.

...and no explanation about what metadata means. Does it mean that "rws" updates the last modified timestamp on the filesystem, and "rwd" doesn't ?

like image 200
Cristian Diaconescu Avatar asked Jan 09 '13 09:01

Cristian Diaconescu


People also ask

What is meaning of RWS in random access file?

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.

What is RWD in java?

Mobile web has brought up a trend that is called responsive web design (RWD). This commonly refers to a technique where the same HTML file is displayed in a bit of a varying manner, based on the screen size of the end user.

Which of the following methods is used in java IO RandomAccessFile to set the offset from the beginning of the stream to where the next read or write will occur?

The java. io. RandomAccessFile. seek(long pos) method sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.


1 Answers

Does it mean that "rws" updates the last modified timestamp on the filesystem, and "rwd" doesn't ?

rws flushes the contents of the file and the modification date of the file.

rwd flushs the contents of the file, but the modification date might not change until the file is closed.

rw only flushes when you tell it to and doesn't change the modifcation date until you close the file.

BTW rwd is much slower for writes than rw, and rws is slower again.

like image 93
Peter Lawrey Avatar answered Sep 22 '22 18:09

Peter Lawrey