【发布时间】:2016-01-25 12:14:50
【问题描述】:
我已阅读此站点上的许多文章,但找不到有效的解决方案。 我正在从 url 下载文件。如果下载中断,我想从中断的地方继续。
源代码:
URL url = new URL("url");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Range",file.length()+"-");
connection.connect();
input = connection.getInputStream();
output = new FileOutputStream("/sdcard/Android/appdata/tmp/tmpdl/something.apk");
byte data[] = new byte[4096];
long total = 0;
int count;
continueDownload = true;
while ((count = input.read(data)) != -1 && continueDownload)
{
total += count;
output.write(data, 0, count);
System.out.println("continueDownload1: " + continueDownload);
}
任何想法!谢谢
【问题讨论】: