Java IO Tutorial - 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;
//from  www  . j ava  2 s .c  o  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();
  }
}