BufferedReader markSupported Example
BufferedReader class markSupported example. This example shows you how to use markSupported method.
BufferedReader class markSupported example.public boolean markSupported() Tells whether this stream supports the mark() operation, which it does.
Here is the code
/*
* @ # MarkSupported.java
* A class repersenting use to markSupported method
* of BufferedReader class in java.io package
* version 29 May 2008
* author Rose India
*/
import java.io.*;
public class MarkSupported {
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, 0, arr.length - 14);
// Call mark after having read all but the last 10
// characters from the StringReader.
if (bufReader.markSupported()) {
bufReader.mark(s.length());
}
// Read the rest of the data from the underlying
// StringReader.
bufReader.read(arr, arr.length - 14, 14);
System.out.println(arr);
// 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.
Reader buffer. |
|