ByteArrayInputStream reset Example

ByteArrayInputStream class reset example. This example shows you how to use reset method.


ByteArrayInputStream class reset example. public void reset() Resets the buffer to the marked position. The marked position is 0 unless another position was marked or an offset was specified in the constructor.

Here is the code

/**
 * @ # Reset.java
 * A class repersenting use to Reset method 
 * of ByteArrayInputStream class in java.io package
 * version 03 June 2008
 * author Rose India 
 */
import java.io.*;

public class Reset {

    public static void main(String args[]) throws Exception {
        byte b[] {123};
        ByteArrayInputStream baStream = new ByteArrayInputStream(b);

        if (baStream.markSupported()) {
            baStream.mark(b.length);
        }

        System.out.println("Byte of data from input stream.");
        //Returns the number of remaining bytes
        while (baStream.available() != 0) {
            //Read  ByteArrayInputStream
            System.out.println(baStream.read());
        }

       
//Reset ByteArrayInputStream

        baStream.reset();
        System.out.println("Byte of data from input stream.");
        while (baStream.available() != 0) {
            System.out.println(baStream.read());
        }


        //Closing  ByteArrayInputStream
        baStream.close();
    }
}

Output
Byte of data from input stream.
1
2
3
Byte of data from input stream.
1
2
3

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

HOME | COPYRIGHT | CONTACT US