SharpZipLib 出错 Wrong Local header signature: 0x21726152

.Net技术 针尖舞 9年前 (2015-08-14) 18030次浏览 1个评论
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.BZip2;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
/**//// <summary>
/// 解压文件
/// </summary>
/// <param name=”args”>包含要解压的文件名和要解压到的目录名数组</param>
public void UnZip(string[] args)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
try
{
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null) //出错
{
string directoryName = Path.GetDirectoryName(args[1]);
string fileName = Path.GetFileName(theEntry.Name);
//生成解压目录
Directory.CreateDirectory(directoryName);
if (fileName != String.Empty)
{
//解压文件到指定的目录
FileStream streamWriter = File.Create(args[1]+fileName);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
}
}
s.Close();
}
catch(Exception eu)
{
throw eu;
}
finally
{
s.Close();
}
}
解压文件应该为.zip 而不是.rar 换一个zip的文件再次执行代码。
用zip的文件进行测试,rar就会出现这个错误。
把文件夹为名称为中文的就没有问题。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明SharpZipLib 出错 Wrong Local header signature: 0x21726152
喜欢 (1)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!

(1)个小伙伴在吐槽
  1. zip压缩包有问题也是会报这个错的
    Kellas2016-07-18 11:16 回复