-2

请告诉我,如何实现 Encoding.GetEncoding ("cp866")?在从存档导出的过程中,俄语符号未正确显示。

public static class ZipArchiveExtension
{
    public static void ExtractToDirectory(this ZipArchive archive, string destinationDirectoryName, bool overwrite)
    {
        if (!overwrite)
        {
            archive.ExtractToDirectory(destinationDirectoryName);
            return;
        }
        foreach (ZipArchiveEntry file in archive.Entries)
        {
            string completeFileName = Path.Combine(destinationDirectoryName, file.FullName);
            if (file.Name == "")
            {
                Directory.CreateDirectory(Path.GetDirectoryName(completeFileName));
                continue;
            }
            file.ExtractToFile(completeFileName, true);
        }
    }
}

FileStream zipToOpen = new FileStream(zipPath, FileMode.Open);
ZipArchive archive = new ZipArchive(zipToOpen);
ZipArchiveExtension.ExtractToDirectory(archive, extractPath, true);
zipToOpen.Dispose();

如 System.IO.Compression: ZipFile.ExtractToDirectory(zipPath, extractPath, Encoding.GetEncoding("cp866"));

4

1 回答 1

2

为了在 a 上使用特定的编码ZipArchive,需要在构造函数中指定。

您应该能够使用 4 参数构造函数:

ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read, false, Encoding.GetEncoding("cp866"));

https://msdn.microsoft.com/en-us/library/hh875101(v=vs.110).aspx

于 2017-02-25T22:22:48.953 回答