ByteArrayOutputStream write(int) in Java

write(int): This method is available in the java.io.ByteArrayOutputStream  class of Java.

Syntax:

void java.io.ByteArrayOutputStream.write(int b)

This method takes one argument. This method writes the specified byte to this ByteArrayOutputStream.

Parameters: One parameter is required for this method.

b: the byte to be written.

Returns: NA

Exceptions: NA

Approach

Java

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

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

        int size = 5;
        ByteArrayOutputStream byteArrayOutputStream =
new ByteArrayOutputStream(size);

        int b = 'a';
        byteArrayOutputStream.write(b);
        System.out.println(byteArrayOutputStream.toString());
        byteArrayOutputStream.close();
    }
}

Output:

a


No comments:

Post a Comment