Java.io.DataInputStream.read() Method

Description

The java.io.DataInputStream.read(byte[] b, int off, int len) method reads len bytes from the contained input stream and allocate them in the buffer b starting at b[off]. The method is blocked until input data is available, an exception is thrown or end of file is detected.

Declaration

Following is the declaration for java.io.DataInputStream.read(byte[] b, int off, int len) method:

public final int read(byte[] b, int off, int len)

Parameters

b - the byte[] into which the data is read from the input stream.

off - the start offset in the b[].

len - the maximum number of bytes read.

Return Value

Total number of bytes read, else -1 if the stream has reached the end.

Exception

IOException -- if an I/O error occurs, the first byte cannot be read, or close() is invoked before this method.

NullPointerException -- if b is null.

IndexOutOfBoundsException -- if len is greater than b.length - off, off is negative, or len is negative