我试图从我的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'功能吗?这里的大图是什么? – 2010-08-05 03:16:09