What does InputStream.available() do in Java?

前端 未结 3 2107
南旧
南旧 2020-11-29 00:36

What does InputStream.available() do in Java? I read the documentation, but I still cannot make it out.

The doc says:

Re

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 01:05

    Blocking doesn't relate to threading or synchronisation here. Instead it relates to blocking IO (see this for more info). If you issue a request to read, and the channel has none available, a blocking call will wait (or block) until data is available (or the channel is closed, throws an exception etc.)

    So why use available() ? So you can determine how many bytes to read, or determine whether you're going to block.

    Note that Java has non-blocking IO capabilities as well. See here for more details

提交回复
热议问题