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[] argsthrows IOException {
        // Create a new StringReader.
        String s = "Rose";
        StringReader r = new StringReader(s);
        char firstLetter = (charr.read();
        // Set the mark.
        if (r.markSupported()) {
            r.mark(0);
        }
        // Continue reading from the string.
        char secondLetter = (charr.read();
        char thirdLetter = (charr.read();
        char fourthLetter = (charr.read();
               // Reset the StringReader.
        r.reset();
        // Get the first character read after the reset.
        char nextLetter = (charr.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

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US