简体   繁体   English

如何将MemoryStream转换为FileStream?

[英]How convert MemoryStream to FileStream?

is work: 工作:

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

not work, memorystream 不工作,记忆流

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

how convert ? 如何转换?

Without knowing more about the ZipInputStream you're using, the only guess I can hazard is that it's trying to use the MemoryStream you're passing it before that stream's position has been reset to the beginning. 在不了解您正在使用的ZipInputStream ,我唯一可以冒险的猜测是它正在尝试使用您正在将该流的位置重置为开头之前传递的MemoryStream Try adding this line before your code snippet: 尝试在代码段之前添加此行:

memoryStream.Seek(0, SeekOrigin.Begin);
FileStream fs = new Filestream();

The call to new Filestream(); 调用new Filestream(); is incorrect. 是不正确的。 FileStream doesn't have any constructors that take zero arguments. FileStream没有任何带零参数的构造函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM