【问题标题】:SharpZipLib returning junk characters when unzipping compressed fileSharpZipLib 在解压缩压缩文件时返回垃圾字符
【发布时间】:2018-04-05 02:36:29
【问题描述】:

我正在尝试使用sharpziplib 解压缩一些文件。问题是,它返回的是垃圾字符而不是特殊字符和日文字符。在获取 zip 文件中的文件之前,是否有将文件名转换为 unicode 的方法? 我目前有以下代码。

 foreach (ZipEntry zipEntry in zf)
                {
                    zipEntry.IsUnicodeText = true;
                    if (!zipEntry.IsFile)
                    {
                        continue;         
                    }

【问题讨论】:

标签: c# zip sharpziplib


【解决方案1】:

所以我在尝试使用 sharpziplib 解码这些文件时运气不佳。我切换到dotnetzip并将编码更改为932,而sharpziplib在解压缩时似乎没有?我将回答我自己的问题,因为我没有看到很多关于这个问题的参考资料,也没有看到其他可能在未来遇到这个问题的人。

 using (ZipFile archive = new ZipFile(archiveFilenameIn, Encoding.GetEncoding(932)))
                {
                    archive.Password = password;
                    archive.Encryption = EncryptionAlgorithm.PkzipWeak; 
                    archive.StatusMessageTextWriter = Console.Out;


                    String fullZipToPath = Path.Combine(outFolder, Path.GetFileNameWithoutExtension(archiveFilenameIn));
                    //string directoryName = Path.GetDirectoryName(fullZipToPath);
                    if (fullZipToPath.Length > 0)
                        Directory.CreateDirectory(fullZipToPath);

                    archive.ExtractAll(fullZipToPath, ExtractExistingFileAction.Throw);
                }

编辑:所以我玩弄了sharpziplib,结果发现我可以设置默认代码页。之后一切正常。

ZipConstants.DefaultCodePage = 932;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-04
    相关资源
    最近更新 更多