如何将一个zip文件原本的目录结构完整的解压出来呢,我用的这个解压方法目前只能把文件解压出来,原本的目录结构没了
2条回答 默认 最新
- 立青_ 2022-02-26 17:23关注
/** * 解压Zip文件 * @param srcPath zip文件路径 * @param targePath 解压路径 * @throws IOException */ public static void unZipFile(String srcPath, String targePath) throws IOException { BufferedInputStream bi; ZipFile zf = new ZipFile(srcPath); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze2 = (ZipEntry) e.nextElement(); String entryName = ze2.getName(); String path = targePath + "/" + entryName; if (ze2.isDirectory()) { Log.d(TAG,"正在创建解压目录 - " + entryName); File decompressDirFile = new File(path); if (!decompressDirFile.exists()) { decompressDirFile.mkdirs(); } } else { Log.d(TAG,"正在创建解压文件 - " + entryName); String fileDir = path.substring(0, path.lastIndexOf("/")); File fileDirFile = new File(fileDir); if (!fileDirFile.exists()) { fileDirFile.mkdirs(); } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(targePath + "/" + entryName)); bi = new BufferedInputStream(zf.getInputStream(ze2)); byte[] readContent = new byte[1024]; int readCount = bi.read(readContent); while (readCount != -1) { bos.write(readContent, 0, readCount); readCount = bi.read(readContent); } bos.close(); } } zf.close(); }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
- ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
- ¥15 MATLAB中streamslice问题
- ¥15 如何在炒股软件中,爬到我想看的日k线
- ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
- ¥15 seatunnel 怎么配置Elasticsearch
- ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
- ¥15 (标签-MATLAB|关键词-多址)
- ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
- ¥500 52810做蓝牙接受端