本文介绍了InputStream.available()在Java中做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 中的 InputStream.available()做什么?我阅读了文档,但我仍然无法解决。

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

文档说:

类InputStream的可用方法总是返回0.

The available method for class InputStream always returns 0.

阻止是什么意思?它只是意味着同步通话吗?

What do they mean by blocking? Does it just mean a synchronized call?

最重要的是,的目的是什么()方法?

推荐答案

阻止与此处的线程或同步无关。相反,它与阻止IO有关(有关详细信息,请参阅)。如果您发出读取请求,并且该通道没有可用,则阻塞调用将等待(或阻止),直到数据可用(或通道关闭,抛出异常等)。

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.)

那么为什么要使用 available()?因此,您可以确定要读取的字节数,或确定是否要阻止。

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

请注意,Java还具有非阻塞IO功能。请参见此处了解更多详情

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

这篇关于InputStream.available()在Java中做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 09:17