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 ww w .  j a  v a  2s .  c o m

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();

  }
}