Cannot unzip files created with Windows “Sent to compressed folder” in scala/java

拟墨画扇 提交于 2020-08-25 05:16:27

问题


I zipped a bunch of IIS log files on a windows 2008 r2 vm by selecting them in Windows Explorer and then using the Send To -> Compressed zipped folder.

I wrote different programs in scala using java.util.ZipFile, zip4j and apache commons compress library.

zip4j returns: Exception in thread "main" net.lingala.zip4j.exception.ZipException: Unknown compression method

commons compress returns: org.apache.commons.compress.compressors.CompressorException: No Compressor found for the stream signature.

java.util.Zip returns: java.util.zip.ZipException: invalid compression method

What is so special about these zip files that none of these methods can unzip them?

How can I unzip them using the JVM libraries?

As an example I used this code: https://stackoverflow.com/a/10634536/832783 to unzip one of the files and it returned the invalid compression method exception.

These are the first 16 bytes in the archive:


回答1:


According to the header information (from the 16 bytes from your post), this entry in the zip file was encrypted using Deflate64. Deflate64 is not to be confused with Deflate compression. Deflate64 is PKWare trademark (PKWare are the maintainers of zip format) and is an enhanced version of Deflate compression algorithm. According to this question on superuser, and this PR on github, Windows uses Deflate64 if the file size is greater than 2GB. zip4j and jdk's zip utility does not support Deflate64 yet, but commons-compress version 1.16 has support for Deflate64. You can probably try using the latest version of commons-compress to unzip your zip file.

Edit: Alternatively, if you have the option, you can try to create the zip file with some other tool (7zip, zip4j, etc). Then you don't have to deal with Deflate64, which makes your zip files compatible with other tools.



来源:https://stackoverflow.com/questions/59431077/cannot-unzip-files-created-with-windows-sent-to-compressed-folder-in-scala-jav

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!