PushbackReader read Example
PushbackReader class read example. This example shows you how to use read method.
PushbackReader class read example.public int read(char[], int, int) throws IOException Reads characters into a portion of an array.
Here is the code
/**
* @ # Read1.java
* A class repersenting use to read method
* of PipedWriter class in java.io package
* version 31 May 2008
* author Rose India
*/
import java.io.*;
public class Read1 {
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. |
|