ByteArrayInputStream read() in Java

read(): This method is available in the java.io.ByteArrayInputStream class of Java.

Syntax:

int java.io.ByteArrayInputStream.read()

This method reads the next byte of data from this input stream.

The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned.

Parameters: NA

Returns: the next byte of data, or -1 if the end of the stream has been reached.

Exceptions: NA

Approach

Java

import java.io.ByteArrayInputStream;
import java.io.IOException;

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

        byte buf[] = { 1, 2, 3, 4 };
        ByteArrayInputStream byteArrayInputStream =
new ByteArrayInputStream(buf);

        System.out.println(byteArrayInputStream.read());
        byteArrayInputStream.close();
    }

}

Output:

1


No comments:

Post a Comment