在文件中保存和加载 MemoryStream [英] Save and load MemoryStream to/from a file

查看:114
本文介绍了在文件中保存和加载 MemoryStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个结构序列化为 MemoryStream 并且我想保存和加载序列化的结构.

I am serializing an structure into a MemoryStream and I want to save and load the serialized structure.

那么,如何将 MemoryStream 保存到文件中并从文件中加载回来?

So, How to Save a MemoryStream into a file and also load it back from file?

推荐答案

您可以使用 MemoryStream.WriteToStream.CopyTo(在框架版本 4.5.2 中支持,4.5.1, 4.5, 4) 将内存流的内容写入另一个流的方法.

You may use MemoryStream.WriteTo or Stream.CopyTo (supported in framework version 4.5.2, 4.5.1, 4.5, 4) methods to write content of memory stream to another stream.

memoryStream.WriteTo(fileStream);

更新:

fileStream.CopyTo(memoryStream);
memoryStream.CopyTo(fileStream);

这篇关于在文件中保存和加载 MemoryStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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