Use FileChannel.force(boolean) or FileDescriptor.sync() to force data to be persistent on disk. Either of them can work. FileChannel.force use FileDispacther.force and it calls fdatasync or fsync in Java 8.
When you use OutputStream.flush, it does not guarantee the data to be written to disk, just flush it to OS. Better to use FileOutputStream.getChannel().force(true) or FileOutputStream.getFD().sync() to guarantee the persistency, performance might not be good.
Special Thanks to Yongkun. He wrote very good blog post. 
Talat Uyarer 9 Ağustos 2016