How do I flush a 'RandomAccessFile' (java)?

前端 未结 6 1658
孤街浪徒
孤街浪徒 2021-02-14 21:44

I\'m using RandomAccessFile in java:

file = new RandomAccessFile(filename, \"rw\");
...
file.writeBytes(...);

How can I ensure that this data i

6条回答
  •  一整个雨季
    2021-02-14 22:10

    Have a look carefully at RandomAccessFile constructor javadoc:

    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.

提交回复
热议问题