Which one is recommended for SYNC on storage device?

Behrooz Nobakht nobeh5 at gmail.com
Sat Jul 26 10:16:48 UTC 2014


Hi,

Prior to Java 7, we'd use

FileOutputStream fos = new FileOutputStream(f);
fos.write(...)
fos.getFD().sync();

As of Java 7, we can say:

OutputStream os = Files.newOutputStream(path, StandardOpenOption.SYNC);

Regarding the behavior and the integrity, which one is more recommended?
Or, are both equivalent in the behavior?

Thanks,
Behrooz


More information about the jdk8-dev mailing list