我正在编写提取将我放置在apk资产文件夹中的zip文件的功能。该功能在android 4.4和android 8.0上运行良好。但它在Android 5.1上返回错误“找不到文件”。我在Assets文件夹中的zip文件大小超过1GB。
以下是我提取zip的代码:
@Override
protected Long doInBackground(Void... voids) {
String filename = "apk.zip";
try {
String[] listAssets = bb.list("");
int countProgress = 0;
for(String s : listAssets){
if(s.equalsIgnoreCase(filename)){
filename = s;
}
}
ZipInputStream zipInputStream = new ZipInputStream(bb.open(filename));
BufferedOutputStream dest = null;
long inputFileSize = getFileSize(filename);
while (true) {
ZipEntry entry = zipInputStream.getNextEntry();
if (entry == null) {
zipInputStream.close();
mThread = null;
break;
}
File file = new File(new StringBuilder(String.valueOf(extractdir)).append(entry.getName()).toString());
if (!entry.isDirectory()) {
BufferedOutputStream dest2;
try {
byte[] data = new byte[8192];
FileOutputStream fileOut = new FileOutputStream(file);
long stepIncrease = inputFileSize/100;
long countStep = 0;
dest2 = new BufferedOutputStream(fileOut, 8192);
while (true) {
if(countStep == stepIncrease) {
countProgress++;
publishProgress(countProgress);
countStep = 0;
}
int count = zipInputStream.read(data, 0, 8192);
if (count == -1) {
break;
}
countStep++;
dest2.write(data, 0, count);
}
dest2.flush();
dest2.close();
dest = dest2;
} catch (Exception e2) {
e2.printStackTrace();
dest2 = dest;
}
} else if (!file.exists()) {
file.mkdirs();
}
}
} catch (Exception e22) {
e22.printStackTrace();
}
return per;
}