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

前端 未结 6 873
野性不改
野性不改 2021-01-13 18:31

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 acc

相关标签:
6条回答
  • 2021-01-13 18:33

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

    0 讨论(0)
  • 2021-01-13 18:34

    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;
    
    0 讨论(0)
  • 2021-01-13 18:41

    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.

    0 讨论(0)
  • 2021-01-13 18:51

    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.

    0 讨论(0)
  • 2021-01-13 18:52

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

    using (ZipFile zipFile = new ZipFile())
    {
      zipFile.AddDirectory(sourceFolderPath);
      zipFile.Save(archiveFolderName);
    }
    
    0 讨论(0)
  • 2021-01-13 18:52

    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

    0 讨论(0)
提交回复
热议问题