Java IO Tutorial - Java BufferedReader.close()








Syntax

BufferedReader.close() has the following syntax.

public void close()  throws IOException

Example

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

//from   ww  w . j a  va2  s .com
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws Exception {
    InputStream is = new FileInputStream("c:/test.txt");

    InputStreamReader isr = new InputStreamReader(is);

    BufferedReader br = new BufferedReader(isr);

    br.close();

    // creates error
    br.read();

  }
}