我在Android中下载大型压缩文件时遇到问题。当我下载小文件(即20 mb)时,一切都还可以,但是当我尝试下载大文件(即100 mb)时,我无法在下载后将其解压缩,因为它已损坏。 这是我的代码:
final URL url = new URL(URL));
final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
File file = new File(mContext.getFilesDir(), params[0]);
file.getParentFile().mkdirs();
FileOutputStream fos;
fos = new FileOutputStream(file);
InputStream input = urlConnection.getInputStream();
BufferedInputStream bis = new BufferedInputStream(input);
byte[] buffer = new byte[1024];
int read = bis.read(buffer);
while(read != -1){
fos.write(buffer, 0, read);
read = bis.read(buffer);
}
fos.close();
bis.close();