What 0 returned by InputStream.read() means? How to handle this?

后端 未结 4 773
不思量自难忘°
不思量自难忘° 2020-12-16 00:10

What 0 (number of bytes read) returned by InputStream.read means? How to handle this situation?

Update: I mean read(byte[] b)

4条回答
  •  鱼传尺愫
    2020-12-16 00:58

    According to Java API Doc:

    http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html#read(byte[])

    It only can happen if the byte[] you passed has zero items (new byte[0]).

    In other situations it must return at least one byte. Or -1 if EOF reached. Or an exception.

    Of course: it depends of the actual implementation of the InputStream you are using!!! (it could be a wrong one)

提交回复
热议问题