帮助从 .Net 创建 Zip 文件并从 Java 读取它们
我正在尝试从 .Net 创建一个可以从 Java 代码读取的 Zip 文件。
我已经使用 SharpZipLib 创建了 Zip 文件,但如果生成的文件根据 #ZipLib 库的 CheckZip 函数有效,并且可以通过 WinZip 或 WinRar 成功解压缩,则在尝试使用 Java 解压缩它时总是会出现错误Java 中的 .Utils.Zip 类。
问题似乎出在 SharpZipLib 编写的错误标头中,我还在 SharpDevelop 论坛上发布了一个问题,但没有结果(请参阅 http://community.sharpdevelop.net/forums/t/8272.aspx 获取信息),但没有结果。
有人有使用 .Net 压缩 Zip 文件并使用 Java.Utils.Zip 类解压缩的代码示例吗?
问候 马西莫
I'm trying to create a Zip file from .Net that can be read from Java code.
I've used SharpZipLib to create the Zip file but also if the file generated is valid according to the CheckZip function of the #ZipLib library and can be successfully uncompressed via WinZip or WinRar I always get an error when trying to uncompress it using the Java.Utils.Zip class in Java.
Problem seems to be in the wrong header written by SharpZipLib, I've also posted a question on the SharpDevelop forum but with no results (see http://community.sharpdevelop.net/forums/t/8272.aspx for info) but with no result.
Has someone a code sample of compressing a Zip file with .Net and de-compressing it with the Java.Utils.Zip class?
Regards
Massimo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我已经使用了 DotNetZip 库,它似乎工作正常。 典型代码:
I have used DotNetZip library and it seems to work properly. Typical code:
我在使用 SharpZipLib(最新版本)创建 zip 并使用 java.utils.zip 提取时遇到了同样的问题。
这就是为我解决问题的方法。 我不得不强制排除 zip64 用法:
I had the same problem creating zips with SharpZipLib (latest version) and extracting with java.utils.zip.
Here is what fixed the problem for me. I had to force the exclusion of the zip64 usage:
无法使用 SharpZipLib 提供帮助,但您可以尝试使用 ZipPackage 类 System.IO。不使用第 3 部分库进行打包(需要 .NET 3+)。
Can't help with SharpZipLib, but you can try to create zip file using ZipPackage class System.IO.Packaging without using 3rd part libraries (requires .NET 3+).
要判断是否真的是符合要求的ZIP文件,请参阅PKZIP的.ZIP文件格式规范。
值得一提的是,我使用 SharpZipLib 在 Windows Mobile 设备上创建 ZIP 并使用 WinZip 或 Windows XP 的内置压缩文件夹功能打开它们没有遇到任何问题,而且使用 SharpZipLib 在桌面上生成 ZIP 并使用我的处理它们也没有遇到任何问题。移动设备上有自己的 ZIP 提取实用程序(基本上是 zlib 的包装器)。
To judge whether it's really a conformant ZIP file, see PKZIP's .ZIP File Format Specification.
For what it's worth I have had no trouble using SharpZipLib to create ZIPs on a Windows Mobile device and open them with WinZip or Windows XP's built-in Compressed Folders feature, and also no trouble producing ZIPs on the desktop with SharpZipLib and processing them with my own ZIP extraction utility (basically a wrapper around zlib) on the mobile device.
您不想在 .NET 中使用 ZipPackage 类 - 它不完全是标准的 zip 模型。 确实如此,但它假定文件中有特定的结构,以及具有众所周知名称的清单,等等。 ZipPackage 似乎已针对 Office 文档和 XPS 文档进行了优化。
第三方库,例如 http://www.codeplex.com/DotNetZip,可能是如果您正在处理通用 ZIP 文件并且想要良好的互操作性,那么最好选择。
DotNetZip 构建的文件与几乎所有内容都具有良好的互操作性,包括 Java 的 java.utils.zip。 但要小心使用 Java 不支持的功能,例如 ZIP64 或 Unicode。 ZIP64 仅对非常大的档案有用,我认为 Java 目前还不能很好地支持这种档案。 Java 以特定方式支持 Unicode,因此如果您使用 DotNetZip 生成基于 Unicode 的 ZIP 文件,您只需遵循一些规则即可正常工作。
You don't wanna use the ZipPackage class in .NET - it isn't quite a standard zip model. Well it is, but it presumes a particular structure in the file, with a manifest with a well-known name, and so on. ZipPackage seems to have been optimized for Office docs and XPS docs.
A third-party library, like http://www.codeplex.com/DotNetZip, is probably a better bet if you are doing general-purpose ZIP files and want good interoperability.
DotNetZip builds files that are very interoperable with just about everything, including Java's java.utils.zip. But be careful using features that Java does not support, like ZIP64 or Unicode. ZIP64 is useful only for very large archives, which Java does not support well at this time, I think. Java supports Unicode in a particular way, so if you produce a Unicode-based ZIP file with DotNetZip, you just have to follow a few rules and it will work fine.
我在 Linux 上解压 SharpZipLib 压缩文件时遇到了类似的问题。 我想我解决了它(我现在在 Linux 和 Mac 上工作,我测试了它),查看我的博客文章:http://igorbrejc.net/development/c/sharpziplib-making-it-work-for-linuxmac
I had a similar problem with unzipping SharpZipLib-zipped files on Linux. I think I solved it (well I works on Linux and Mac now, I tested it), check out my blog post: http://igorbrejc.net/development/c/sharpziplib-making-it-work-for-linuxmac