ByteArrayInputStream close Example

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


ByteArrayInputStream class close example. public void close() throws IOException Closing a ByteArrayInputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

Here is the code

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

public class Mark {

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

        System.out.println(baStream.read());
        /*if (baStream.markSupported()) {
            baStream.mark(b.length);
        }*/
        baStream.reset();
        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());
        }

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

Here is the code

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

public class Close {

    public static void main(String args[]) throws Exception {

        byte b[] {12345};
        ByteArrayInputStream baStream = new ByteArrayInputStream(b);

        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());
        }

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

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

HOME | COPYRIGHT | CONTACT US