【问题标题】:Unzip file from zip archive of multiple files using ZipFile class使用 ZipFile 类从多个文件的 zip 存档中解压缩文件
【发布时间】:2010-06-04 14:01:35
【问题描述】:

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

【问题讨论】:

  • 如果 zip 文件在 assets 目录中,路径名是什么?将其复制到应用程序文件目录是我的最佳选择吗?
  • 一个 APK 已经是一个压缩的 ZIP 档案。将 ZIP 放入 APK 是浪费时间 - 只需将 APK 的内容放入其中即可。

标签: android unzip zipfile


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-05
    • 1970-01-01
    • 2020-07-10
    • 2021-11-23
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多