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);
}
在这段代码中,我尝试恢复下载。目标文件为20MB。但是,当我停止在10mb上下载,然后遇到麻烦时,我得到的文件大小为30MB。似乎它继续写入文件,但不能部分从服务器下载。Wget -c非常适合该文件。如何恢复文件下载?
喵喵时光机
翻翻过去那场雪