Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用ZipFile类从多个文件的zip存档解压缩文件_Android_Unzip_Zipfile - Fatal编程技术网

Android 使用ZipFile类从多个文件的zip存档解压缩文件

Android 使用ZipFile类从多个文件的zip存档解压缩文件,android,unzip,zipfile,Android,Unzip,Zipfile,我想使用ZipFile类从多个文件的存档中使用文件名解压缩文件。如何获取要传递给ZipFile构造函数的zip文件名和目录字符串?您可以使用AssetManager和ZipInputStream 如果zip文件位于assets目录中,那么路径名是什么?将其复制到应用程序文件目录是我的最佳选择吗?APK已经是压缩的ZIP存档。把一个拉链放在APK里面是浪费时间——只要把APK的内容放进去就行了。 ZipInputStream in = null; try { final String z

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

您可以使用AssetManager和ZipInputStream


如果zip文件位于assets目录中,那么路径名是什么?将其复制到应用程序文件目录是我的最佳选择吗?APK已经是压缩的ZIP存档。把一个拉链放在APK里面是浪费时间——只要把APK的内容放进去就行了。
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;
}