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

前端 未结 6 1667
孤街浪徒
孤街浪徒 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 21:52

    here's what i do in my app:

    rf.close();
    rf = new RandomAccessFile("mydata", "rw");
    

    this is give 3-4times gain in performance compared to getFd().sync() and 5-7 times compared to "rws' mode

    deoes exactly what the original question proposed: passes on unsaved data to the OS and out of JVM. Doesn't physically write to disk, and therefore introduces no annoying delays

提交回复
热议问题