Help in creating Zip files from .Net and reading them from Java

允我心安 提交于 2019-12-01 06:55:20
Panos

I have used DotNetZip library and it seems to work properly. Typical code:

using (ZipFile zipFile = new ZipFile())
{
  zipFile.AddDirectory(sourceFolderPath);
  zipFile.Save(archiveFolderName);
}

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:

ZipOutputStream s = new ZipOutputStream(File.Create(someZipFileName))

s.UseZip64 = UseZip64.Off;

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+).

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.

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.

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

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