Java PushbackInputStream mark() Example

PushbackInputStream class mark() method example. This example shows you how to use mark() method.


Syntax is : public void mark(int readlimit)
This method marks the current position in this input stream. The mark method of PushbackInputStream does nothing.

Here is the code.

/**
 * @(#) MarkPushbackInputStream.java
 * A class representing use of method mark() of PushbackInputStream 
class in java.io Package.
 * @Version  10-June-2008
 @author   Rose India Team
 */
import java.io.*;

public class MarkPushbackInputStream {

    public static void main(String[] argsthrows IOException {

        byte[] byteArray = new byte[]{'M''A''H''E''N''D''R''A'};

        /* Create object of ByteArrayOutputStream class to write specified 
        byte array to the output byte stream. */
        ByteArrayOutputStream objByteStream = new ByteArrayOutputStream();
        objByteStream.write(byteArray, 08);

        // Create object of ByteArrayInputStream class.
        InputStream objInStream = new ByteArrayInputStream(byteArray);

        //Create object of MarkSupportedFilterInputStream class.
        PushbackInputStream obj = new PushbackInputStream(objInStream);

        // Read from the input stream buffer.
        char firstChar = (charobj.read();

        // Set the mark position for first element.
        obj.mark(1);
        System.out.println("Element at first position has marked but The " +
                "mark method of \nPushbackInputStream does nothing.");

        System.out.print("Content of the file : " + firstChar);
        for (int c = obj.read(); c != -1; c = obj.read()) {
            System.out.print((charc);
        }
    }
}

output of the program.
 Element at first position has marked but The mark method of
PushbackInputStream does nothing.
Content of the file : MAHENDRA

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

HOME | COPYRIGHT | CONTACT US