我在 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();