1

这是我显示问题的简单测试代码:

URL u = new URL(someURLString);
URLConnection c = u.openConnection();
InputStream is = c.getInputStream();

int amount = c.getContentLength(); //gives 75830, which is correct

int r = 0;
while (is.read() != -1) //count input
    r++;

//r is 65878, what the hell?

显然有数据丢失。谁能解释这种行为?

先感谢您

4

2 回答 2

2

这个问题现在已经 6 个月大了,所以我不知道你是否在此期间解决了你的问题。但...

我在 Android 应用程序上运行 HttpUrlConnection 时遇到了同样的问题。logcat上的内容不完整!我将内容写入设备上的文件,它向我展示了整个内容。也许这似乎是 logcat 的一个问题,但我花了几个小时!

于 2013-05-10T08:23:39.747 回答
-1

c.getContentLength();- 返回内容长度标头字段的值。只需检查您收到的内容是否正确

于 2012-10-19T17:38:13.987 回答