Java BufferedOutputStream .write (byte[] b, int off, int len)

Syntax

BufferedOutputStream.write(byte[] b, int off, int len) has the following syntax.

public void write(byte[] b,  int off,  int len)  throws IOException

Example

In the following code shows how to use BufferedOutputStream.write(byte[] b, int off, int len) method.


//www  .  j  a  v a  2 s  .  co  m

import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;

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

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BufferedOutputStream bos = new BufferedOutputStream(baos);

    byte[] bytes = { 1, 2, 3, 4, 5 };

    bos.write(bytes, 0, 5);

    bos.flush();

    for (byte b : baos.toByteArray()) {
      System.out.print(b);
    }

  }
}

The code above generates the following result.