使用ZipFile类从多个文件的zip存档解压缩文件

时间:2010-06-04 14:01:35

标签: android unzip zipfile

我想使用ZipFile类从多个文件的存档中使用其名称解压缩文件。如何获取要传递给ZipFile构造函数的zip文件名和目录的字符串?

1 个答案:

答案 0 :(得分:4)

您可以使用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;
}
相关问题