Android:从服务器下载大文件

时间:2016-08-10 17:38:03

标签: android http download

在我的Android应用程序中,我使用以下命令从服务器(1GB)下载大文件:

connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setReadTimeout(7000);
connection.connect();
input = connection.getInputStream();
output = new FileOutputStream("/sdcard/Android/" + fileName, true);

byte data[] = new byte[1024];
int count;

int total = 0;
while (count = input.read(data)) > 0) {
total = total + count;
output.write(data, 0, count);
}

代码效果很好。但有时下载的文件已损坏,我不知道为什么!是否有机制或算法,库...以保证100%成功下载?请帮忙,我不知道该怎么做!我不想使用校验和检查文件是否正常,如果没有,则再次下载!我想要一个解决方案来检测问题,同时下载并立即修复损坏的部分!

0 个答案:

没有答案
相关问题