I am using RandomAccessFile to perform some writes to a file as part of a transaction. Before I commit my transaction, I want to be absolutely sure that the data is written to disk.
Calling force(boolean)
on the RAF's FileChannel
appears to provide this guarantee, but is it called implicitly when I close the file, or do I have to call it manually?
Also, does anybody have any insight into what force()
actually does, and how far it can be trusted? Is it possible that the OS may report that the data has been written to disk, when in fact it is still sitting in some cache somewhere? To what extent is this OS/HDD/filesystem-dependent?