1
    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);

        }

    }

I tried to resume download. But If my file is 5200kb, and I resume download after 100kb, I got file 5300kb. What's wrong with this code?

POMATu
  • 3,422
  • 7
  • 30
  • 42
  • 1
    does the answer at http://stackoverflow.com/questions/4593275/resume-download-not-working-in-android work for you? – ahmedre Jun 12 '11 at 12:33
  • Have you verified that the server support ranges? – Kaj Jun 12 '11 at 13:23
  • Yes it support ranges. Just tested. I don't see the difference, but it WORKS! Thanks! – POMATu Jun 12 '11 at 13:29
  • 2
    @POMATu: can you please answer the question yourself and then accept that answer? Also, you need to accept answers to previous questions if they fix your problem. – Zecas May 16 '12 at 16:09

0 Answers0