我正试图从我的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();
Run Code Online (Sandbox Code Playgroud) 谁能告诉我如何在从 Android 中的服务器(可能是 http、ftp 或其他)下载文件之前获取文件的大小?流媒体是否有效?请帮我..
问候瓦内什