无法解压缩使用 Windows“发送到压缩文件夹"创建的文件在 Scala/Java 中 [英] Cannot unzip files created with Windows "Sent to compressed folder" in scala/java

查看:42
本文介绍了无法解压缩使用 Windows“发送到压缩文件夹"创建的文件在 Scala/Java 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 2008 r2 虚拟机上压缩了一堆 IIS 日志文件,方法是在 Windows 资源管理器中选择它们,然后使用发送到 -> 压缩的压缩文件夹.

我使用 java.util.ZipFile、zip4j 和 apache commons 压缩库在 Scala 中编写了不同的程序.

zip4j 返回:线程main"中的异常 net.lingala.zip4j.exception.ZipException:未知压缩方法

commons compress 返回:org.apache.commons.compress.compressors.CompressorException:未找到用于流签名的压缩器.

java.util.Zip 返回:java.util.zip.ZipException:压缩方法无效

这些 zip 文件有什么特别之处,以至于这些方法都无法解压它们?

如何使用 JVM 库解压缩它们?

作为一个例子,我使用了这个代码:

解决方案

根据标题信息(来自您帖子的 16 个字节),zip 文件中的此条目已使用 Deflate64 加密.不要将 Deflate64 与 Deflate 压缩混淆.Deflate64 是 PKWare 商标(PKWare 是 zip 格式的维护者),是 Deflate 压缩算法的增强版本.根据这个问题 在超级用户上,以及 this PR 在 github 上,Windows 使用 Deflate64如果文件大小大于 2GB.zip4j 和 jdk 的 zip 实用程序尚不支持 Deflate64,但 commons-compress 1.16 版已支持 Deflate64.您或许可以尝试使用最新版本的 commons-compress 来解压您的 zip 文件.

或者,如果您有选择,您可以尝试使用其他工具(7zip、zip4j 等)创建 zip 文件.那么您就不必处理 Deflate64,它使您的 zip 文件与其他工具兼容.

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:

解决方案

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.

这篇关于无法解压缩使用 Windows“发送到压缩文件夹"创建的文件在 Scala/Java 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆