ByteArrayOutputStream toString Example

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


ByteArrayOutputStream class toString example. public String toString() Converts the buffer's contents into a string decoding bytes using the platform's default character set. The length of the new String is a function of the character set, and hence may not be equal to the size of the buffer.

Here is the code

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

public class Write {

    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, 04);
        System.out.println(oStream.toString());

        oStream.close();
    }
}

Output
Rose

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

HOME | COPYRIGHT | CONTACT US