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[] 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