ByteArrayOutputStream reset Example

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


ByteArrayOutputStream class reset example.public void reset() Resets the count field of this byte array output stream to zero, so that all currently accumulated output in the output stream is discarded.

Here is the code

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

public class Reset {

    public static void main(String args[]) throws Exception {
        ByteArrayOutputStream oStream = new ByteArrayOutputStream();

        String s = "Rose India";
        byte b[] = s.getBytes();

        // Writes byte array into this byte array output stream.
        oStream.write(b);
        System.out.println(oStream.toString());

        //Resets  byte array output stream 
        oStream.reset();
        oStream.write('a');
        System.out.println(oStream.toString());

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

Output
Rose India
New String

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

HOME | COPYRIGHT | CONTACT US