android - Assets Manager 在 Android 5.1 上找不到文件
问题描述
我正在编写提取我放置在 apk 资产文件夹中的 zip 文件的函数。该功能在 android 4.4 和 android 8.0 上运行良好。但它在 android 5.1 上返回错误“找不到文件”。我在资产文件夹中的 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;
}
解决方案
推荐阅读
- python - DataFrame Corr(),找不到列索引
- python - 使用 lmfit 绘制和建模数据 - 拟合与数据不匹配。我究竟做错了什么?
- python - 如何修复流量会话表不存在错误?
- reactjs - 向 Antd Table 添加可编辑行?
- python - 字典中存在检查列表项
- apache-spark - 在 PySpark 中创建一个类的 Apache Spark RDD
- html - 这个按钮如何在可见和隐藏之间切换
- angular - 角度常数文件导出
- syntax - 在 Verilog 中使用任务使 LED 闪烁
- angular - Angular 组件测试用例出错:类型错误:无法读取未定义的属性“contractno”