【发布时间】:2012-06-22 14:16:04
【问题描述】:
为了下载东西,我使用 apache 类 HTTPResponse HTTPClient 等。 我检查这样的有效下载:
entity.writeTo(new FileOutputStream(outfile));
if(outfile.length()!=entity.getContentLength()){
long fileLength = outfile.length();
outfile.delete();
throw new Exception("Incomplete download, "+fileLength+"/"
+entity.getContentLength()+" bytes downloaded");
}
但似乎从未触发异常。如何正确处理? entity.getContentLength 是服务器上文件的长度还是接收到的数据量?
【问题讨论】:
-
我会警告不要使用 entity.getContentLength,因为它似乎总是返回 -1 存在问题,请看这些:stackoverflow.com/q/5897191/346309stackoverflow.com/q/3418106/346309stackoverflow.com/q/3617507/346309。我只想远离你的方法,使用更可靠的 MD5 校验和。
标签: android http-headers httpresponse