October 22, 2024
Chicago 12, Melborne City, USA
java

How to flush a RandomAccessFile?


I use "rw" mode and want to flush content into device:

RandomAccessFile random= new RandomAccessFile(path.toFile(), "rw");
random.write(1);

But they always failed on flush operation:

//Force failed
random.getChannel().force(true);

or

//sync failed
random.getFD().sync();

There is no detail reason:

sync failed
java.io.SyncFailedException: sync failed
    at java.io.FileDescriptor.sync(Native Method)

Other modes also produce the same error:"rwd","rws". Why and how to solve?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video