android - 使用 ZipFile 类从多个文件的 zip 存档中解压文件

标签 android unzip zip

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

最佳答案

您可以使用 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;
}

关于android - 使用 ZipFile 类从多个文件的 zip 存档中解压文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2974798/

相关文章:

android - android中的ActionBar和滑出菜单

Java解压程序

java - 在内存中为 google App Engine Java 解压

python - 存档意外结束

windows-phone-7 - 从 WP7 上的独立存储中解压缩文件

java - Java 压缩中的 FileNotFound 错误

Android点击时更改背景颜色

java - LeakCanary 检测到我的 Java Android 应用程序中的泄漏 - Google map

Android recyclerview-selection 实现?

java - 在应用程序的内部存储中提取 Zip 文件 - Android?