【发布时间】:2017-07-10 20:41:15
【问题描述】:
我尝试了几个字节的while循环方法和下面的这个方法:
try {
URL dl = null;
dl = new URL("http://ds-forums.com/kyle-tests/uploads/Screenshots.zip");
ReadableByteChannel rbc = Channels.newChannel(dl.openStream());
FileOutputStream fos = new FileOutputStream(fileName + "Screenshots.zip");
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
System.out.println(fos.getChannel().size());
fos.close();
rbc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
但是这些方法并不是非常有效/快速。我发现了 apache Utils 并且我正在使用
IOUtils.copy(new URL("http://ds-forums.com/kyle-tests/uploads/Screenshots.zip").openStream(), new FileOutputStream(System.getProperty("user.home").replace("\\", "/") + "/Desktop/Screenshots.zip"));
但这是最好的方法吗?我现在很困惑哪种方法最适合下载 26mb 的压缩文件。 (上面的文件只有1mb 我正在测试方法)
我只是想看看其他人是否遇到过这个问题,也许他们可以帮助我。谢谢。
【问题讨论】:
-
建议多线程下载文件。看看 jDownloader 源代码。
标签: java apache-commons