StringReader class close() method example
Closes the stream and releases any system resources associated with it.
StringReader class close()method example. This example shows you how to use close()method.This method Closes the stream and releases any system resources associated with it.
Here is the code:-
/**
* @Program that Closes the stream and releases any system resources associated
* with it
* Close.java
* Author:-RoseIndia Team
* Date:-29-May-2008
*/
import java.io.*;
public class Close {
public static void main(String[] args) {
try {
String s = "Girish";
//creating the String Reader
StringReader sr = new StringReader(s);
//creating char array
char[] c = new char[s.length()];
// Reads a single character.
sr.read(c);
//Displays the given array
System.out.print("The given Array is: ");
System.out.println(c);
// Closes the stream and releases any system resources associated with it.
sr.close();
//throw an IOException.
sr.read(c);
System.out.println(c);
} catch (IOException e) {
System.out.println(e.toString());
}
}
}
|
Output of the program:-
The given Array is: Girish
java.io.IOException: Stream closed |
|