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可以很好地处理这个文件。如何恢复文件下载?
https://stackoverflow.com/questions/6237079
复制相似问题