使用特定编码读取 ZipArchive
Use specific encoding for reading ZipArchive
请告诉我,如何实现 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"));
为了在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
请告诉我,如何实现 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"));
为了在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