【发布时间】:2010-08-05 03:12:13
【问题描述】:
我正在尝试从我的 Yahoo! 下载一个大文件。如果下载没有在 100 秒内完成,显然是设置(不是我)断开下载的网站服务器。该文件足够小,通常可以成功传输。在数据速率较慢和下载断开连接的情况下,有没有办法在断开连接的文件偏移处恢复 URLConnection?代码如下:
// Setup connection.
URL url = new URL(strUrl[0]);
URLConnection cx = url.openConnection();
cx.connect();
// Setup streams and buffers.
int lengthFile = cx.getContentLength();
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(strUrl[1]);
byte data[] = new byte[1024];
// Download file.
for (total=0; (count=input.read(data, 0, 1024)) != -1; total+=count) {
publishProgress((int)(total*100/lengthFile));
output.write(data, 0, count);
Log.d("AsyncDownloadFile", "bytes: " + total);
}
// Close streams.
output.flush();
output.close();
input.close();
【问题讨论】:
-
也许使用雅虎网站服务器以外的东西 :) Android 没有
scp功能吗?这里的大局是什么?