Reader MarkSupported() Example
Tells whether this stream supports the mark() operation.
Reader class MarkSupported() method example. This example shows you how to use MarkSupported() method.This method Tells whether this stream supports the mark() operation.
Here is the code:-
/**
* @Program that Tells whether this stream supports the mark() operation.
* MarkSupported.java
* Author:-RoseIndia Team
* Date:-5-jun-2008
*/
import java.io.*;
public class MarkSupported {
public static void main(String[] args)throws IOException {
// Create a new StringReader.
String s = "Roseindia";
StringReader r = new StringReader(s);
char firstLetter = (char) r.read();
// Set the mark.
if (r.markSupported()) {
r.mark(0);
}
boolean b=r.markSupported();
System.out.println("This stream supports the mark() operation: "+b);
// Continue reading from the string.
char secondLetter = (char) r.read();
char thirdLetter = (char) r.read();
char fourthLetter = (char) r.read();
char fifthLetter = (char) r.read();
char SixthLetter = (char) r.read();
char SeventhLetter = (char) r.read();
char eightthLetter = (char) r.read();
char ninthLetter = (char) r.read();
// Reset the StringReader.
r.reset();
// Get the first character read after the reset.
char nextLetter = (char) r.read();
System.out.println("The next letter after reset is: " +
nextLetter);
// Close the StringReader.
r.close();
}
}
|
Output of the Program
This stream supports the mark() operation: true
The next letter after reset is: o |
|