使用ZipFile类从多个文件的zip压缩文件解压缩文件
问题描述:
我想使用ZipFile
类从多个文件的压缩文件中使用其名称解压缩文件。我怎样才能得到zip文件名和目录的字符串传递给ZipFile
构造函数?使用ZipFile类从多个文件的zip压缩文件解压缩文件
答
您可以使用AssetManager和ZipInputStream http://developer.android.com/reference/android/content/res/AssetManager.html
ZipInputStream in = null;
try {
final String zipPath = "data/sample.zip";
// Context.getAssets()
in = new ZipInputStream(getAssets().open(zipPath));
for (ZipEntry entry = in.getNextEntry(); entry != null; entry = in.getNextEntry()) {
// handle the zip entry
}
} catch (IOException e) {
Log.e(TAG, e.getMessage());
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ignored) {
}
in = null;
}
的路径是什么名字,如果压缩文件是在资产目录?我最好将它复制到应用程序文件目录中吗? – CalvinS 2010-06-04 14:33:31
APK已经是压缩的ZIP压缩文件。在APK中放入ZIP是浪费时间 - 只需将APK的内容放在那里即可。 – CommonsWare 2010-06-04 16:04:05