Unzip file from zip archive of multiple files using ZipFile class

那年仲夏 提交于 2019-12-18 17:25:38

问题


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?


回答1:


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;
}


来源:https://stackoverflow.com/questions/2974798/unzip-file-from-zip-archive-of-multiple-files-using-zipfile-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!