ByteArrayOutputStream write() method in Java with Examples

The write() method of ByteArrayOutputStream class in Java is used in two ways:

1. The write(int) method of ByteArrayOutputStream class in Java is used to write the specified byte to the ByteArrayOutputStream. This specified byte is passed as integer type parameter in this write() method. This write() method writes single byte at a time.

Syntax:

public void write(int b)

Specified By: This method is specified by write() method of OutputStream class.

Parameters: This method accepts one parameter b which represents the byte to be written.

Return value: The method does not return any value.

Exceptions: This method does not throw any exception.

Below program illustrates write(int) method in ByteArrayOutputStream class in IO package:

Program: