1、使用jdk自带的解压报错java.util.zip.ZipException: only DEFLATED entries can have EXT descriptor
2、解决方案使用apache的ant解压
org.apache.tools.zip
3、引入pom

    <!-- https://mvnrepository.com/artifact/org.apache.ant/ant --><dependency><groupId>org.apache.ant</groupId><artifactId>ant</artifactId><version>1.10.5</version></dependency>

import com.weihui.member.gateway.enums.ErrorCode;
import com.weihui.member.gateway.exception.BizException;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;/*** chentao*/
public class ZipUtilApache {private static final Logger log  = LoggerFactory.getLogger(ZipUtilApache.class);private static final int buffer = 2048;/*** 解压Zip文件** @param path 文件目录*/public static void unZip(String path) {int count = -1;String savepath = "";File file = null;InputStream is = null;FileOutputStream fos = null;BufferedOutputStream bos = null;savepath = new File(path).getParent() + File.separator; //保存解压文件目录new File(savepath).mkdir(); //创建保存目录ZipFile zipFile = null;try {zipFile = new ZipFile(path, "gbk"); //解决中文乱码问题Enumeration<?> entries = zipFile.getEntries();while (entries.hasMoreElements()) {byte buf[] = new byte[buffer];ZipEntry entry = (ZipEntry) entries.nextElement();String filename = entry.getName();boolean ismkdir = false;if (filename.lastIndexOf("/") != -1) { //检查此文件是否带有文件夹ismkdir = true;}filename = savepath + filename;if (entry.isDirectory()) { //如果是文件夹先创建file = new File(filename);file.mkdirs();continue;}file = new File(filename);if (!file.exists()) { //如果是目录先创建if (ismkdir) {new File(filename.substring(0, filename.lastIndexOf("/"))).mkdirs(); //目录先创建}}file.createNewFile(); //创建文件is = zipFile.getInputStream(entry);fos = new FileOutputStream(file);bos = new BufferedOutputStream(fos, buffer);while ((count = is.read(buf)) > -1) {bos.write(buf, 0, count);}bos.flush();bos.close();fos.close();is.close();}zipFile.close();} catch (IOException ioe) {log.error("ZipUtilApache-unZip-IOException",ioe);throw new BizException(ErrorCode.SYSTEM_ERROR,"解压缩商户资质文件["+path+"]失败","解压缩商户资质文件["+path+"]失败");} finally {try {if (bos != null) {bos.close();}if (fos != null) {fos.close();}if (is != null) {is.close();}if (zipFile != null) {zipFile.close();}} catch (Exception e) {log.error("ZipUtilApache-unZip-Exception",e);}}}public static void main(String[] args) {unZip("E:\\下载\\mgs1\\test\\GI20210303173812PXPKRV2304.zip");// unZip("E:\\下载\\mgs1\\test\\47kong.zip");}
}

下面是出现报错的

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;/*** 解压指定zip文件至当前文件* @param unZipfileName  需要解压的zip文件名*/public void unZip(String unZipfileName){FileOutputStream fileOut = null;File file;try{this.zipIn = new ZipInputStream(new BufferedInputStream(new FileInputStream(unZipfileName)));while((this.zipEntry = this.zipIn.getNextEntry()) != null){file = new File(new File(unZipfileName).getParent()+File.separator+this.zipEntry.getName());if(this.zipEntry.isDirectory()){file.mkdirs();} else {//如果指定文件的目录不存在,则创建之.File parent = file.getParentFile();if(!parent.exists()){parent.mkdirs();}fileOut = new FileOutputStream(file);while(( this.readedBytes = this.zipIn.read(this.buf) ) > 0){fileOut.write(this.buf , 0 , this.readedBytes );}if(fileOut != null) {try {fileOut.close();} catch (IOException e) {e.printStackTrace();}}}this.zipIn.closeEntry();}}catch(Exception ioe){ioe.printStackTrace();} finally {if(this.zipIn != null) {try {this.zipIn.close();} catch (IOException e) {e.printStackTrace();}}if(fileOut != null) {try {fileOut.close();} catch (IOException e) {e.printStackTrace();}}}}

java.util.zip.ZipException: only DEFLATED entries can have EXT descriptor相关推荐

  1. java.util.zip.ZipException: error in opening zip file

    今天在eclipse上新建了一个java项目,将其打包为jar文件,上传到linux上进行运行时出错了:错误内容为: java.util.zip.ZipException: error in open ...

  2. java.util.zip.zipexception_android-如何解决java.util.zip.ZipException?

    每当我尝试调试和部署我的android应用程序(在Android Studio 0.9中)时,都会出现以下错误: Execution failed for task ':app:packageAllD ...

  3. 启动TOMCAT报错 java.util.zip.ZipException: invalid LOC header (bad signature)

    报错信息大致如下所示: at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)at java.lang.reflect.M ...

  4. java.util.zip.zipexception_Java 压缩zip异常,java.util.zip.ZipException: duplicate entry: 问题...

    在测试过程中看到后台打印的日志出现异常,发现这也是历史遗留问题java.util.zip.ZipException: duplicate entry: 111111.txt at java.util. ...

  5. 编译环境与生成环境的JDK版本不一样,报:java.util.zip.ZipException: error in opening zip file

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 发布应用 ...

  6. Poi读取Excle报错 java.util.zip.ZipException: invalid stored block lengths

    一:Poi读取Excle报错  java.util.zip.ZipException: invalid stored block lengths 系统中需要导出excle签收单,excle模板是预设好 ...

  7. CAS单点登录个性化用户界面报错:Caused by: java.util.zip.ZipException: invalid entry CRC

    报错信息: 2019-07-06 19:18:38,398 ERROR [org.apache.catalina.core.ContainerBase] - <A child container ...

  8. 记录一个坑:java.util.zip.ZipException: zip file is empty

    接手一个离职同事的项目,运行起来没问题但是kotlin还用的是 1.3.70版本,这都2021年了,还用这么低版本果断换成1.5.30版本,同步一下没问题,运行~~~~~~  java.util.zi ...

  9. EasyPoi读取word时报错java.util.zip.ZipException: Unexpected record signature: 0X9

    场景:把word模板放入类路径目录下,程序读取word模板,填充数据,导出. 现象:报错java.util.zip.ZipException: Unexpected record signature: ...

  10. java.util.zip.ZipException: duplicate entry: android/support/v4/text/TextUtilsCompat.class

    最近在开发中遇到了这样的一个错误 Error:Execution failed for task ':FriendLogistics:transformClassesWithJarMergingFor ...

最新文章

  1. 利用堆排序查找数组中第K小的元素方法
  2. 设计模式——开发常用的设计模式梳理
  3. ASP.NET状态管理
  4. Java 8系列之重新认识HashMap(转载自美团点评技术团队)
  5. gulp自动添加版本号
  6. 手机MMI体系结构及其实现
  7. jquery响应式内容滑动插件bxSlider
  8. 浙大PAT的大量感悟
  9. table表格字母无法换行
  10. LongAdder类学习笔记
  11. FreeSWITCH折腾笔记3——数据库修改为postgresql
  12. 莫烦python之python基础学习备忘
  13. cad.net 块裁剪边界反向修剪
  14. 更好玩的跑步机,还有丰富课程资源,赤兔Air跑步机体验
  15. 算法创作|模拟商品加入购物车并结算价钱问题解决方法
  16. usleep java_sleep()和usleep()的使用和区别
  17. 使用Python与图灵机器人聊天
  18. linux定时运行命令
  19. 手机的短消息实现目前有三种方法(转)
  20. Mysql报表统计常用sql

热门文章

  1. 存储卡规格等级全解!SD卡TF卡都能用
  2. Tab表格thead头部固定(demo)
  3. 计算机十六进制ABCD,16进制计算(十六进制计算器在线)
  4. Instruments之相关介绍(一)
  5. 超火的微信渐变国旗头像,一键生成!!
  6. 祝牛年吉祥,前程似锦,吉星高照,财运亨通,合家欢乐,飞黄腾达,福如东海,寿比南山,幸福美满,官运亨通,美梦连连。
  7. 仿XP画图板—升级版
  8. 含有使字的诗句_带有一字的诗句
  9. android 木马行为监控,基于行为分析的Android手机木马检测技术研究
  10. Linux系统中,让alias命令永久保存的方法!