【发布时间】:2017-05-10 04:05:08
【问题描述】:
在 Android 文档中:https://developer.android.com/reference/java/net/HttpURLConnection.html 我们可以发现:-1 是 inputstream 的结尾,这意味着我们到达了 http 响应的结尾
getContentLength() 返回传输的字节数,不能用于预测可以从 getInputStream() 读取压缩流的字节数。相反,读取该流直到它耗尽,即当 read() 返回 -1 时。
为什么-1可以代表http响应
【问题讨论】:
-
All
InputStreams 使用该约定。