Java IO Tutorial - Java ByteArrayOutputStream .write (int b)








Syntax

ByteArrayOutputStream.write(int b) has the following syntax.

public void write(int b)

Example

In the following code shows how to use ByteArrayOutputStream.write(int b) method.

// w  ww .  j a v a2 s.  c o  m

import java.io.ByteArrayOutputStream;
import java.io.IOException;

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

    // write byte array to the output stream
    baos.write(55);

    // converts the byte to the default charset value
    String str = baos.toString();

    // prints the string
    System.out.println(str);

  }
}

The code above generates the following result.