从多个文件的zip压缩包使用的ZipFile类解压缩文件文件、多个、压缩包、解压缩

2023-09-05 08:59:35 作者:素颜姑娘

我想使用的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;
}
 
精彩推荐
图片推荐