从多个文件的zip压缩包使用的ZipFile类解压缩文件 [英] Unzip file from zip archive of multiple files using ZipFile class

查看:168
本文介绍了从多个文件的zip压缩包使用的ZipFile类解压缩文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的ZipFile 类使用其名称来自多个文件的归档文件解压缩文件。我怎样才能得到压缩文件名和目录的字符串传递给的ZipFile 的构造函数?

I'd like to use the ZipFile class to unzip a file using its name from an archive of multiple files. How can I get the string of the zip file name and directory to pass to the ZipFile constructor?

推荐答案

您可以使用AssetManager和ZipInputStream http://developer.android.com/reference/android/content/res /AssetManager.html

You can use the AssetManager and 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;
}

这篇关于从多个文件的zip压缩包使用的ZipFile类解压缩文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆