我在使用 2000 年的 Windows 版本 4 的旧 PKZIP® 命令行创建的 zip 文件时遇到问题。我正在使用 ICSharpCode.SharpZipLib 来提取文件。Windows 在资源管理器中打开文件没有问题。这是代码:
private void Extract(string zipFile, string outputfolder)
{
try
{
_logger.InfoFormat("Extracting {0}", zipFile);
System.IO.Stream stream = new System.IO.FileStream(zipFile, System.IO.FileMode.Open);
ZipInputStream zipInputStream = new ZipInputStream(stream);
ZipEntry zipEntry = zipInputStream.GetNextEntry(); //Throws Compression error exception
while (zipEntry != null)
{
String entryFileName = zipEntry.Name;
_logger.InfoFormat("Entry-Filename: {0}", entryFileName);
byte[] buffer = new byte[4096];
String fullZipToPath = Path.Combine(outputfolder, entryFileName);
string directoryName = Path.GetDirectoryName(fullZipToPath);
if (directoryName.Length > 0)
{
Directory.CreateDirectory(directoryName);
}
using (FileStream streamWriter = File.Create(fullZipToPath))
{
StreamUtils.Copy(zipInputStream, streamWriter, buffer);
}
zipEntry = zipInputStream.GetNextEntry();
}
}
catch (Exception ex)
{
_logger.Error("Error during extraction",ex);
throw;
}
}
知道如何解决这个问题吗?