java解压压缩包工具类
16lz
2021-04-10
/** * * @param zipFile 压缩包文件 * @param descDir 解压缩文件存放路径 * @return */ public static boolean unzip(File zipFile, String descDir) { try (ZipArchiveInputStream inputStream = getZipFile(zipFile)) { File pathFile = new File(descDir); if (!pathFile.exists()) { pathFile.mkdirs(); } ZipArchiveEntry entry; while ((entry = inputStream.getNextZipEntry()) != null) { String name = entry.getName(); if (entry.isDirectory()) { File directory = new File(descDir, name); directory.mkdirs(); } else { OutputStream os = null; try { os = new BufferedOutputStream(new FileOutputStream(new File(descDir, name))); //输出文件路径信息 IOUtils.copy(inputStream, os); } finally { IOUtils.closeQuietly(os); } } } } catch (Exception e) { logger.error("[unzip] 解压zip文件出错", e); return false; } return true; } private static ZipArchiveInputStream getZipFile(File zipFile) throws Exception { return new ZipArchiveInputStream(new BufferedInputStream(new FileInputStream(zipFile)),"utf-8", true); }
©著作权归作者所有:来自51CTO博客作者遗梦江湖的原创作品,如需转载,请注明出处,否则将追究法律责任
更多相关文章
- python异常处理
- DenyHosts阻止SSH暴力***
- 执行git push出现
- 复制远程服务器文件命令scp的使用
- 关于word导出功能的一些技巧步骤提高效率很实用!!!
- 如何在 指定文件夹 快速打开 jupyter notebook
- 【MOS】如何利用RMAN可传输表空间迁移数据库到不同字节序的平台(
- 利用zimbra clientuploader实现文件上传
- java中的IO整理