Java FileDescriptor.sync()

Syntax

FileDescriptor.sync() has the following syntax.

public void sync()  throws SyncFailedException

Example

In the following code shows how to use FileDescriptor.sync() method.


import java.io.FileDescriptor;
import java.io.FileOutputStream;
/* w ww  .ja  va2  s . co  m*/
public class Main {
  public static void main(String[] argv) throws Exception {
    FileOutputStream os = new FileOutputStream("outfilename");
    FileDescriptor fd = os.getFD();
    os.write(1);
    os.flush();
    fd.sync();
  }
}