如何将MemoryStream转换为FileStream?

3

工作内容:

using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFile)))
{
  ZipEntry theEntry;
  while ((theEntry = s.GetNextEntry()) != null)
  {
  }
}

不工作,内存流

using (ZipInputStream s = new ZipInputStream(memorystream))
{
    ZipEntry theEntry;
    while ((theEntry = s.GetNextEntry()) != null)//Exception **EOF in header**
    {
    }
}

如何转换?

1
什么有效?什么无效?错误?异常?它们是什么?您需要提供所有相关信息。 - Oded
你得到了什么异常?任何数据流都应该可以工作。 - driis
你从哪里获取ZipInputStream - JaredPar
2个回答

13

如果你使用的 ZipInputStream 没有更多信息,我唯一能猜测的是它试图在 MemoryStream 流的位置被重置之前使用它。尝试在你的代码片段前添加这行代码:

memoryStream.Seek(0, SeekOrigin.Begin);

1
+1,因为这是基于提供的信息的一个非常好的猜测。 - driis
那个,今天早些时候我遇到了一个非常类似的问题。 :) - Adam Maras

2
FileStream fs = new Filestream();

调用new Filestream();是不正确的。 FileStream没有任何接受零个参数的构造函数。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接