Java InputStream.close()

Syntax

InputStream.close() has the following syntax.

public void close()  throws IOException

Example

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


//w ww .  j  a  v  a  2  s  .c  o m
import java.io.FileInputStream;
import java.io.InputStream;

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

    // new input stream created
    InputStream is = new FileInputStream("C://test.txt");

    // invoke available
    int i = is.available();

    // number of bytes available is printed
    System.out.println(i);

    // releases any system resources associated with the stream
    is.close();

    // throws io exception on available() invocation
    i = is.available();
    System.out.println(i);

  }
}