恢复http下载。文件附加,但大小更大

时间:2011-06-12 12:24:42

标签: java android http download resume-download

    URL url;

    url = new URL("http://download.thinkbroadband.com/5MB.zip");

      File fileThatExists = new File("/sdcard/testfile"); 

      URLConnection conexion = url.openConnection();
      conexion.setRequestProperty("Range", "bytes=" + fileThatExists.length() + "-");
    // Resume download.

    conexion.setRequestProperty("If-Range", "Mon, 02 Jun 2008 15:30:42 GMT"); 

    conexion.connect();
    InputStream input = new BufferedInputStream(url.openStream());
    OutputStream output = new FileOutputStream("/sdcard/testfile", true);

    byte data[] = new byte[1024];

    long total = 0;

    int i = 0; 
    while ((count = input.read(data)) != -1) {
        total += count;
        i++;
        output.write(data, 0, count);

        }

    }

我试图恢复下载。但如果我的文件是5200kb,并且我在100kb之后恢复下载,我得到文件5300kb。这段代码出了什么问题?

0 个答案:

没有答案