【发布时间】:2011-03-19 04:41:12
【问题描述】:
我在服务器中有 40 MB 的文件,我正在使用
下载我的文件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);
此代码似乎运行良好,但花费的时间太长。他们有什么办法可以让这个过程更快。
/minhaz
【问题讨论】:
-
您只能以最慢的连接速度下载。如果您使用拨号 (56K),则优化无关紧要。最慢的连接不一定是你 - 它不是与服务器的直接连接,请求会通过众多网络到达那里并返回。
标签: android io filereader