BufferedReader close Example
BufferedReader class close example. This example shows you how to use close method.
BufferedReader class close example. public void close() throws IOException Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.
Here is the code
/*
* @ # Close.java
* A class repersenting use to close method
* of BufferedReader class in java.io package
* version 29 May 2008
* author Rose India
*/
import java.io.*;
public class Close {
public static void main(String args[])throws Exception {
// Create a new instance of a BufferedReader object using
// a StringReader.
String s = "This is the internal StringReader buffer.";
StringReader stringReader = new StringReader(s);
BufferedReader bufReader = new BufferedReader(stringReader);
// Read from the underlying StringReader.
char[] arr = new char[s.length()];
bufReader.read(arr);
System.out.println(arr);
// Close the BufferedReader object and the underlying
// StringReader object.
stringReader.close();
bufReader.close();
}
} |
Output
| This is the internal StringReader buffer. |
|