Reader Reset() Example
Resets the stream.
Reader class Reset() method example. This example shows you how to use Reset() method.This method Resets the stream.
Here is the code:-
/**
* @Program that Resets the stream.
* Reset.java
* Author:-RoseIndia Team
* Date:-5-jun-2008
*/
import java.io.*;
public class Reset {
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
|
|