Java IO Tutorial - Java ByteArrayOutputStream(int size) Constructor








Syntax

ByteArrayOutputStream(int size) constructor from ByteArrayOutputStream has the following syntax.

public ByteArrayOutputStream(int size)

Example

In the following code shows how to use ByteArrayOutputStream.ByteArrayOutputStream(int size) constructor.

//from ww  w.j  ava  2 s  .c  o m
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class Main {
  public static void main(String[] args) throws IOException {

    byte[] bs = { 65, 66, 67, 68, 69, 70, 71, 72 };

    OutputStream os = new ByteArrayOutputStream();

    ByteArrayOutputStream baos = new ByteArrayOutputStream(200);

    baos.write(bs);

    baos.writeTo(os);

    System.out.println(os.toString());

  }
}

The code above generates the following result.