Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将物理zip文件转换为System.IO.Stream对象_C#_Stream_Zip_Converter - Fatal编程技术网

C# 如何将物理zip文件转换为System.IO.Stream对象

C# 如何将物理zip文件转换为System.IO.Stream对象,c#,stream,zip,converter,C#,Stream,Zip,Converter,如何将物理zip文件转换为System.IO.Stream对象? 我试过- System.IO.Stream=File.ReadAllBytes(路径+“\\”+“ZipFile.zip”) StreamReader stream=newstreamreader(路径+“\\”+“ZipFile.zip”) System.IO.Stream=newfilestream(路径+“\\”+“ZipFile.zip”,FileMode.Open);stream.Close() 他们似乎都没有工作 尝试

如何将物理zip文件转换为System.IO.Stream对象? 我试过-

  • System.IO.Stream=File.ReadAllBytes(路径+“\\”+“ZipFile.zip”)
  • StreamReader stream=newstreamreader(路径+“\\”+“ZipFile.zip”)
  • System.IO.Stream=newfilestream(路径+“\\”+“ZipFile.zip”,FileMode.Open);stream.Close()
  • 他们似乎都没有工作
    尝试读取流时,它会说流不可读
    或者文件在目标位置似乎已损坏,无法解压缩

  • 无法将其编译(将
    字节[]
    转换为
    )。。。所以,我不确定您是如何在这里得到运行时错误的
  • StreamReader
    不是一个流-不确定您希望在这里进行什么转换
  • 看起来您立即关闭了流—这似乎是唯一一行与标题匹配并会产生确切的运行时错误的行。修正-在完成读取之前不要关闭流

  • 查看SharpZipLib的
    ZipInputStream


    通过

    尝试此代码。要使用此代码,您必须下载


    将它用作流只会将其作为字节流读取,它不会知道它是一个zip文件,也不会尝试解压缩它。你能提供一些代码吗?你试过GZipStream或Deflatesttream吗+建议使用DotNetZip,这是一种用于Zip文件管理的非常先进的工具。
    using Ionic.Zip;
    using Ionic.Crc;
    using System.IO;
    
    protected void Page_Load(object sender, EventArgs e)
        {
    
    using (ZipFile zip = ZipFile.Read(ZipPath))
        {
    
            foreach (ZipEntry entry in zip)
            {
    
                CrcCalculatorStream reader = entry.OpenReader();
                MemoryStream memstream = new MemoryStream();
                reader.CopyTo(memstream);
                byte[] bytes = memstream.ToArray();
                System.IO.Stream stream = new System.IO.MemoryStream(bytes); 
    
    
            }
        }
    }