BufferedReader reset Example
BufferedReader class reset example. This example shows you how to use reset method.
BufferedReader class reset example.public void reset() throws IOException Resets the stream to the most recent mark.
Here is the code
/**
* @ # Reset.java
* A class repersenting use to reset method
* of InputStreamReader class in java.io package
* version 28 May 2008
* author Rose India
*/
import java.io.*;
public class Reset {
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, arr.length - 12, 12);
System.out.println(arr);
// Call mark after having read all but the last 10
// characters from the StringReader.
if (bufReader.markSupported()) {
bufReader.mark(s.length());
}
// Call reset and then re-read from the underlying
// StringReader.
bufReader.reset();
char[] arr2 = new char[s.length()];
bufReader.read(arr2);
System.out.println(arr2);
// Close the BufferedReader object and the underlying
// StringReader object.
stringReader.close();
bufReader.close();
}
} |
Output
This is the
internal StringReader buffer.
|
|