httpurlconnection.setReadTimeout() 到底是做什么的?

What exactly does httpurlconnection.setReadTimeout() do?

根据 java 文档 connection.setReadTimeout() - "A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout."

那么如果我设置一定的读取超时时间,然后开始下载文件,如果达到超时时间,下载会中断吗?

还是仅当指定超时没有任何内容可读时它才会中断?

只有没有响应才会抛出异常。获取数据时不会中断,所以不用担心。

如果您开始下载文件并且没有中断,则不会发生超时。

如果您将超时设置为 30 秒。如果您下载了 15 秒,在这 15 秒后连接失败,您将需要再等待 30 秒才能超时。

每次调用 recv() 函数时读取超时重新开始。

所以正确答案是(2)。