Really force file sync/flush in Java
How can data written to a file really be flushed/synced with the block device by Java. I tried this code with NIO: FileOutputStream s = new FileOutputStream(filename) Channel c = s.getChannel() while(xyz) c.write(buffer) c.force(true) s.getFD().sync() c.close() I supposed that c.force(true) togehter with s.getFD().sync() should be sufficient because the doc for force states Forces any updates to this channel's file to be written to the storage device that contains it. If this channel's file resides on a local storage device then when this method returns it is guaranteed that all changes made