java - 如何通过 ProgressDialog 从外部存储中的资产中提取 zip 文件
问题描述
这是我的代码,我认为 doInBackground 方法没有运行,此代码生成目标文件夹但它是空的,我想在目标文件夹中提取 myzipfile.zip
在 MainActivity 中获取 zip 文件的路径
String zipFilename = this.getAssets().openFd("raw/"+"myzipfile.zip")";
String unzipLocation = Environment.getExternalStorageDirectory() + "/targetfolder";
final Decompress d = new Decompress(zipFilename, unzipLocation);
d.execute();
制作用于在后台解压缩的 Decompree 类
private class Decompress extends AsyncTask<Void, Integer, Integer> {
private String _zipFile;
private String _location;
private int per = 0;
@Override
protected Integer doInBackground(Void... params) {
try {
ZipFile zip = new ZipFile(_zipFile);
mProgressDialog.setMax(zip.size());
FileInputStream fin = new FileInputStream(_zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + ze.getName());
if (ze.isDirectory()) {
_dirChecker(ze.getName());
} else {
per++;
publishProgress(per);
FileOutputStream fout = new
FileOutputStream(_location + ze.getName());
for (int c = zin.read(); c != -1; c = zin.read()) {
fout.write(c);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch (Exception e) {
Log.e("Decompress", "unzip", e);
}
return null;
}}}
解决方案
推荐阅读
- vue.js - 在开发模式下构建时指定资产输出目录
- python - 使用来自文件 excel 序列项 0 中的数组数据的 nltk 进行错误标记:预期的 str 实例,找到列表
- css - CSS font-face - 何时使用多个 src 描述符
- c# - .NET Core Difference between Hosted Service and Singleton Service
- c# - Asp.NET MVC 5 更新导航属性
- uml - UML 状态机 - 具有条目活动的复合状态中的显式条目
- python - 从按钮功能创建的对象中检索值的问题
- javascript - 在 npm 或 webpack 中分离开发和生产文件
- python-3.x - 排序一个zip对象后,为什么列出对象为空
- random-forest - 随机森林库 zip 文件