StringReader class ready()method example
Tells whether this stream is ready to be read.
StringReader class ready()method example. This example shows you how to use ready()method.This method Tells whether this stream is ready to be read.
Here is the code:-
/**
* @Program that Tells whether this stream is ready to be read.
* Ready.java
* Author:-RoseIndia Team
* Date:-29-May-2008
*/
import java.io.*;
public class Ready {
public static void main(String[] args) {
try {
String s = "Girish";
//Creating a Stream reader
StringReader reader = new StringReader(s);
//Tells whether this stream is ready to be read.
boolean b = reader.ready();
System.out.println("Stream is Ready: " + b);
char[] arr = new char[s.length()];
// Reads a single character.
reader.read(arr);
System.out.print("The array is: ");
System.out.print(arr);
// Closes the stream
reader.close();
boolean b1 = reader.ready();
System.out.println("Stream is Ready: " + b1);
} catch (IOException e) {
System.out.println(e.toString());
}
}
}
|
Output of the program:-
Stream is Ready: true
The array is: Girishjava.io.IOException: Stream closed |
|