PushbackReader ready Example
PushbackReader class ready example. This example shows you how to use ready method.
PushbackReader class ready example.public boolean ready() throws IOException Tells whether this stream is ready to be read.
Here is the code
/**
* @ # Ready.java
* A class repersenting use to Ready method
* of PipedWriter class in java.io package
* version 31 May 2008
* author Rose India
*/
import java.io.*;
public class Ready {
public static void main(String args[]) throws Exception {
// Create a new instance of a PushbackReader object with an
// underlying StringReader buffer.
String s = "This is the internal buffer of StringReader.";
StringReader stringReader = new StringReader(s);
PushbackReader reader = new PushbackReader(stringReader, 100);
// Read from the underlying StringReader buffer.
char[] arr = new char[s.length()];
reader.read(arr, 0, arr.length);
System.out.println(arr);
// "Unread" some of the data read from the underlying
// StringReader buffer.
String newS = "Replacement internal buffer.";
char[] newSArr = newS.toCharArray();
reader.unread(newSArr);
// Close the PushbackReader object and the underlying
// StringReader object.
stringReader.close();
reader.close();
}
} |
Output
| This is the internal buffer of StringReader. |
|