Reader Mark() Example
Marks the present position in the stream.
Reader class Mark() method example. This example shows you how to use Mark() method.This method Marks the present position in the stream.
Here is the code:-
/**
* @Program that Marks the present position in the stream.
* Mark.java
* Author:-RoseIndia Team
* Date:-5-jun-2008
*/
import java.io.*;
public class Mark {
public static void main(String[] args) throws IOException {
// Create a new StringReader.
String s = "Rose";
StringReader r = new StringReader(s);
char firstLetter = (char) r.read();
// Set the mark.
if (r.markSupported()) {
r.mark(0);
}
// Continue reading from the string.
char secondLetter = (char) r.read();
char thirdLetter = (char) r.read();
char fourthLetter = (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
| The next letter after reset is: o |
|