117 Program to demonstrate ByteArrayOutputStream in Java

Code:
/*
Program to demonstrate ByteArrayOutputStream in Java
*/

import java.io.*;

class ByteOutputDemo
{
public static void main(String args[]) throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();

String s1 = "Coding";
String s2 = " Atharva";


baos.write(s1.getBytes());
baos.write(s2.getBytes());

System.out.println(baos.toString());
System.out.println("Size Before Reset: "+baos.size());

baos.reset();
System.out.println("Size After Reset: "+baos.size());

}
}

Ouput:

ByteArrayOutputStream in Java

Previous
Next Post »