ByteArrayOutputStream close Example

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


ByteArrayOutputStream class close example.public void close() throws IOException Closing a ByteArrayOutputStream 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

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

public class Close {

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

        ByteArrayOutputStream oStream = new ByteArrayOutputStream();

        String s = "Rose India";
        byte bs[] = s.getBytes();
        //Writes a byte to the byte array output stream.
        oStream.write(bs);
        byte b[] = oStream.toByteArray();
        for (int i = 0; i < b.length; i++) {
            System.out.print((char)b[i]);
        }

        //Closing a ByteArrayOutputStream has no effect.
        oStream.close();
    }
}

Output
Rose India

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

HOME | COPYRIGHT | CONTACT US