压缩/解压 zip 时遇到 java.lang.IllegalArgumentException: MALFORMED

错误详情:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.IllegalArgumentException: MALFORMED
at java.util.zip.ZipCoder.toString(ZipCoder.java:58)
at java.util.zip.ZipFile.getZipEntry(ZipFile.java:529)
at java.util.zip.ZipFile.access$900(ZipFile.java:56)
at java.util.zip.ZipFile$1.nextElement(ZipFile.java:511)
at java.util.zip.ZipFile$1.nextElement(ZipFile.java:481)
at org.zeroturnaround.zip.ZipUtil.iterate(ZipUtil.java:366)
at org.zeroturnaround.zip.ZipUtil.unpack(ZipUtil.java:772)
at org.zeroturnaround.zip.ZipUtil.unpack(ZipUtil.java:755)

at com.webthk.map.utils.ImageCutUtil.main(ImageCutUtil.java:29)


解决办法:

将原有解压插件换为基于org.apache.ant 的解压方法

另,解压rar可以用java-unrar-0.3.jar解决 (参考http://blog.csdn.net/zheng2008hua/article/details/6998345)

(参考http://www.blogjava.net/icewee/archive/2012/05/26/379267.html)

原因:

有两种可能:java路径问题 将 " \ " 换为 " \\ " 即可

是因为java.util.zip下的格式转换有问题 ,jdk中的zip存在字符编码的问题。windows下压缩的默认编码是GBK(话说可以通过修改jdk解决,技术难度也太高了,未亲测)



你可能感兴趣的:(java)