我試圖從我的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