您的位置:首页 > 编程语言 > Java开发

readFully(byte[] b)是自适应解决读取流中多少字节问题的(当然由参数byte个数决定),有则读满,流结尾时则自动退出阻塞,详细见JDK帮助

2012-10-05 18:07 363 查看

readFully

public void readFully(byte[] b)
throws IOException

Reads some bytes from an input stream and stores them into the buffer array
b
. The number of bytes read is equal to the length of
b
.
This method blocks until one of the following conditions occurs:

b.length
bytes of input data are available, in which case a normal return is made.
End of file is detected, in which case an
EOFException
is thrown.
An I/O error occurs, in which case an
IOException
other than
EOFException
is thrown.

If
b
is
null
, a
NullPointerException
is thrown. If
b.length
is zero, then no bytes are read. Otherwise, the first byte read is stored into element
b[0]
, the next one into
b[1]
, and so on. If an exception is thrown from this method, then it may be that some but not all bytes of
b
have been updated with data from the input stream.

Parameters:
b
- the buffer into which the data is read. Throws:
EOFException
- if this stream reaches the end before reading all the bytes.
IOException
- if an I/O error occurs.

还有一点参数off要注意:off是表示目的字节数组的起始位置的偏移量

void
, int, int)]readFully(byte[] b, int off, int len)


從串流中讀取
len
個位元組,並將其存儲到
b
中(從索引
off
開始)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: