中央目录记录的C#到底能不能找到 [英] c# End of Central Directory record could not be found
问题描述
我下载使用C#程序中的zip文件,我得到的错误
I am downloading a zip file using c# program and I get the error
at System.IO.Compression.ZipArchive.ReadEndOfCentralDirectory()
at System.IO.Compression.ZipArchive.Init(Stream stream, ZipArchiveMode mode,
Boolean leaveOpen)
at System.IO.Compression.ZipArchive..ctor(Stream stream, ZipArchiveMode mode,
Boolean leaveOpen, Encoding entryNameEncoding)
at System.IO.Compression.ZipFile.Open(String archiveFileName, ZipArchiveMode
mode, Encoding entryNameEncoding)
at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileN
ame, String destinationDirectoryName, Encoding entryNameEncoding)
at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileN
ame, String destinationDirectoryName)
下面是节目
response = (HttpWebResponse)request.GetResponse();
Stream ReceiveStream = response.GetResponseStream();
byte[] buffer = new byte[1024];
FileStream outFile = new FileStream(zipFilePath, FileMode.Create);
int bytesRead;
while ((bytesRead = ReceiveStream.Read(buffer, 0, buffer.Length)) != 0)
outFile.Write(buffer, 0, bytesRead);
outFile.Close();
response.Close();
try
{
ZipFile.ExtractToDirectory(zipFilePath, destnDirectoryName);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}
我不明白的错误。任何人都可以解释这种
由于
先生
I do not understand the error. Can anybody explain this Thanks MR
推荐答案
从你删你的老问题。
我得到System.IO.InvalidDataException:中央目录记录的到底能不能找到
I get System.IO.InvalidDataException: End of Central Directory record could not be found.
这任何文件你传递最有可能的方式是畸形和邮编失败。既然你已经有硬盘驱动器上的文件 OUTFILE
我会建议试图打开该文件与内置的ZIP提取窗口,看看它是否工作。如果失败的问题是不是与你解压码但与服务器发送给您的数据。
This most likely means whatever file you are passing in is malformed and the Zip is failing. Since you already have the file outfile
on the hard drive I would recommend trying to open that file with with windows built in zip extractor and see if it works. If it fails the problem is not with your unzipping code but with the data the server is sending to you.
这篇关于中央目录记录的C#到底能不能找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!