URL url = new URL("http://download.thinkbroadband.com/20MB.zip");
URLConnection connection = url.openConnection();
File fileThatExists = new File(path);
OutputStream output = new FileOutputStream(path, true);
connection.setRequestProperty("Range", "bytes=" + fileThatExists.length() + "-");
connection.connect();
int lenghtOfFile = connection.getContentLength();
InputStream input = new BufferedInputStream(url.openStream());
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
output.write(data, 0 , count);
}
Run Code Online (Sandbox Code Playgroud)
在这段代码中我尝试恢复下载.目标文件是20MB.但是当我停止下载10mb,然后contunue时,我得到文件大小为30MB的文件.它似乎继续写入文件,但无法从服务器部分下载.Wget -c适合这个文件.如何恢复文件下载?