这是我的代码,我认为doInBackground方法未运行,此代码使targetfolder变为空,我想在targetfolder中提取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;
}}}