加快下载时间 [英] Speed Up download time
问题描述
我在服务器40 MB的文件,我用我的下载文件
I have 40 MB file in server and i am downloading my file using
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
FileOutputStream f = new FileOutputStream(new File("trips.xml"));
InputStream in = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ( (len1 = in.read(buffer)) != -1 ) {
f.write(buffer,0, len1);
这code似乎工作正常,但它花费的时间太长。是他们的任何方式,我可以让这个过程更快。
this code seems working fine but it is taking too long. is their any way I can make this process faster.
/ minhaz
推荐答案
本<打击>非常丑陋的黑客其中罢工>的也许的给你一个更快的下载时间,也可能是不,你有你的条件下进行测试:
This very ugly hack which might give you a faster download time, or maybe it doesn't, you'll have to test it under your conditions:
开始几个平行连接(在单独的线程),并且每一个应该下载不同的组块数据的(使用的 HTTP 1.1 Range头)。这取决于很多事情一样,如果有一个满月,或太阳出来或玫瑰绽放,你可能会得到更好的效果,因为它会饱和你的链接比单一连接(每个人的牺牲更好别人分享你的链接,有点像BitTorrent的是什么呢)。
Start several parallel connections (in separate threads?), and each one should download a different chunk of data (using HTTP 1.1 Range header). Depending on many things like if there's a full moon, or the sun is out or the roses are blooming you might get better results because it will saturate your link better than a single connection (to the expense of everyone else sharing your link, kinda like what BitTorrent does).
这篇关于加快下载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!