请告诉我,如何实现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”));
答案 0 :(得分:1)
为了在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