Java IO Tutorial - Java FileOutputStream.close()








Syntax

FileOutputStream.close() has the following syntax.

public void close()  throws IOException

Example

In the following code shows how to use FileOutputStream.close() method.

//from  www. jav a  2s.  com

import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {

    FileOutputStream fos = new FileOutputStream("C://text.txt");

    fos.close();

    // try to write into underlying stream
    fos.write(65);
    fos.flush();
    fos.close();

  }
}