如何将MemoryStream转换为FileStream?

发布于 2024-10-08 20:18:29 字数 422 浏览 1 评论 0原文

是工作:

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**
    {
    }
}

如何转换?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

追风人 2024-10-15 20:18:29

在不了解有关您正在使用的 ZipInputStream 的更多信息的情况下,我唯一可以冒险的猜测是它正在尝试使用您在该流的位置之前传递给它的 MemoryStream重置到开始。尝试在代码片段之前添加此行:

memoryStream.Seek(0, SeekOrigin.Begin);

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. Try adding this line before your code snippet:

memoryStream.Seek(0, SeekOrigin.Begin);
倥絔 2024-10-15 20:18:29
FileStream fs = new Filestream();

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

FileStream fs = new Filestream();

The call to new Filestream(); is incorrect. FileStream doesn't have any constructors that take zero arguments.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文