在java中下载的恢复文件已损坏

时间:2016-09-07 07:54:57

标签: java android android-asynctask download resume

我在崩溃后实施了简历下载 中断,我成功地做到了,但现在我变得腐败了 文件。任何人都可以帮我解决这个问题。

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;

                }

0 个答案:

没有答案