找不到中央目录记录的末尾 [英] End of Central Directory record could not be found

查看:1636
本文介绍了找不到中央目录记录的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#程序下载一个zip文件,并且在System.IO.Compression.ZipArchive中收到错误

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();
    }

我不理解该错误。谁能解释这个
谢谢
MR

I do not understand the error. Can anybody explain this Thanks MR

推荐答案

问题是 ZipFile 找不到表明归档已结束的代码行,因此:

The problem is ZipFile can't find the line of code that signals the end of the archive, so either:


  1. 存档已损坏。

  1. The archive is corrupt.


  • 解决方案-存档需要修复。

这不是.zip存档。

It is not a .zip archive.


  • 它可能是.rar或其他压缩类型。或者我在这里怀疑,您正在下载一个自动重定向到zip文件的html文件。

  • 解决方案-必须找到使用此代码的正确档案。


  • 一个多段zip文件。

  • 解决方案-解压缩前先读取所有文件。


  • 解决方案-检查文件属性/权限并验证文件名。

使用您喜欢的zip / unzip实用程序(7-zip,winzip等)打开文件将告诉您可能是哪种。

Opening the file with your favorite zip/unzip utility (7-zip, winzip, etc) will tell which of these it could be.

这篇关于找不到中央目录记录的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆