【发布时间】:2012-09-06 19:09:08
【问题描述】:
我对这个奇怪的问题感到震惊。
我正在使用以下方法下载文件:
public boolean downloadSection(String link,String fileLocation,long currentlyDownloadedBytes){
try {
RandomAccessFile file = new RandomAccessFile(fileLocation, "rw");
file.seek(currentlyDownloadedBytes+1);
URL imageUrl = new URL(link);
HttpURLConnection conn =(HttpURLConnection)imageUrl.openConnection();
conn.setRequestProperty("Range", "bytes=" + currentlyDownloadedBytes + "-");
conn.setConnectTimeout(100000);
conn.setReadTimeout(100000);
conn.setInstanceFollowRedirects(true);
InputStream is=conn.getInputStream();
byte buffer[]=new byte[1024];;
while (true) {
// Read from the server into the buffer
int read = is.read(buffer);
if (read == -1) {
break;
}
// Write buffer to file
file.write(buffer, 0, read);
}
file.close();
return true;
} catch (Exception ex){
ex.printStackTrace();
return false;
}
}
当我使用此代码下载 mp3 文件时,下载文件 打开良好,但下载的 android 应用程序(.apk 文件)在打开时会出现 Package Parsing Error 图像永远不会打开。
请帮忙 谢谢
【问题讨论】:
标签: android download random-access download-manager