Java实现多线程下载及断点续传(二)

2014-11-24 08:44:51 · 作者: · 浏览: 2
osf.seek(http.getContentLength() - 1);
osf.write(0);
} else {
osf = new RandomAccessFile(f, "rw");
osf.seek(http.getContentLength() - 1);
osf.write(0);
}
System.out.println("temp 文件长度:" + f.length());
Thread t;// 下载子线程,
for (int j = 0; j < tn; j++) {
if (j == tn - 1) {// 如果最后一个线程则加上余数长度字节
bn = len + (http.getContentLength() % tn);
} else {
bn = len;
}
System.out
.println("t" + j + "线程下载长度:" + bn + "起始字节:" + len * j);
t = new Main(j, urlt, fileName, len * j, bn
);
t.start();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
作者:罗盛力