Java IO Tutorial - 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.

/*w  w  w . java2 s . c  o  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.