用java下载的恢复文件已损坏
我已经在崩溃或崩溃后下载了简历 打断一下,我成功地做到了,但是现在我得到了一个坏消息 文件谁能帮我解决这个问题用java下载的恢复文件已损坏,java,android,android-asynctask,download,resume,Java,Android,Android Asynctask,Download,Resume,我已经在崩溃或崩溃后下载了简历 打断一下,我成功地做到了,但是现在我得到了一个坏消息 文件谁能帮我解决这个问题 URL url = new URL(f_url[0]); HttpURLConnection conection =(HttpURLConnection) url.openConnection(); conection.setDoInput(true); conection.setDoOutput(true);
URL url = new URL(f_url[0]);
HttpURLConnection conection =(HttpURLConnection) url.openConnection();
conection.setDoInput(true);
conection.setDoOutput(true);
if (downloadstatus) {
file = new File(DESTINATION_PATH + f_url[1] + EXTEN);
if (file.exists()) {
downloaded = (int) file.length();
conection.setRequestProperty("Range", "bytes=" + (file.length()) + "-");
} else {
conection.setRequestProperty("Range", "bytes=" + downloaded + "-");
}
lenghtOfFile= conection.getContentLength();
conection.connect();
input = new BufferedInputStream(conection.getInputStream());
output=(downloaded==0)? new FileOutputStream(DESTINATION_PATH + f_url[1] + EXTEN): new FileOutputStream(DESTINATION_PATH + f_url[1] + EXTEN,true);
bout = new BufferedOutputStream(output, 1024);
byte[] data = new byte[1024];
int x = 0;
long total = 0;
while ((x = input.read(data, 0, 1024)) >= 0) {
total += x;
publishProgress(""+(int)((total*100)/lenghtOfFile));
bout.write(data, 0, x);
downloaded += x;
}
最终下载的大小是多少?预计大小是多少?大约1GB。那么,您的下载大小是多少?和预期的相比,你说它被破坏了,有些东西丢失了,对吗?你试过什么来调试这个?您的下载量是1字节还是?我的下载量约为1024字节。最终下载的大小是多少?预计的大小是多少?大约为1GB。那么,您的下载量是多少?和预期的相比,你说它被破坏了,有些东西丢失了,对吗?你试过什么来调试这个?你是减少了1字节还是?我大约减少了1024字节。