StringReader class markSupported()method example
Tells whether this stream supports the mark() operation, which it does.
StringReader class markSupported()method example. This example shows you how to use markSupported()method.This method Tells whether this stream supports the mark() operation, which it does.
Here is the code:-
/**
* @Program that Tells whether this stream supports the mark() operation,
which it does.
* MarkSupported.java
* Author:-RoseIndia Team
* Date:-29-May-2008
*/
import java.io.*;
public class MarkSupported {
public static void main(String[] args) {
try {
// Create a new StringReader.
String s = "RoseIndia";
StringReader reader = new StringReader(s);
// Read from the underlying string one at a time.
char l = (char) reader.read();
// Set the mark.
if (reader.markSupported()) {
// Marks the present position in the stream
reader.mark(0);
}
boolean b=reader.markSupported();
System.out.println(" Reader supports the mark() operation:"+b);
// Continue reading from the string.
char l1 = (char) reader.read();
char l2 = (char) reader.read();
char l3 = (char) reader.read();
char l4 = (char) reader.read();
// Reset the StringReader.
reader.reset();
// Get the first character read after the reset.
char nextLetter = (char) reader.read();
System.out.println("The next letter Readed after reset is: " +
nextLetter);
// Close the StringReader.
reader.close();
} catch (IOException ex) {
System.out.println(ex.toString());
}
}
}
|
Output of the program:-
Reader supports the mark() operation:true
The next letter Readed after reset is: o |
|