从文件保存和载入的MemoryStream到/ [英] Save and load MemoryStream to/from a file

查看:160
本文介绍了从文件保存和载入的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.WriteTo Stream.CopyTo (在Framework版本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天全站免登陆