创建文件并使用的MemoryStream保存到它 [英] create file and save to it using memorystream

查看:3676
本文介绍了创建文件并使用的MemoryStream保存到它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个文件,然后使用内存流写呢?
我需要使用的MemoryStream,以防止其他线程试图访问该文件。

How can i create a file and write to it using the memory stream? I need to use the memorystream to prevent other threads from trying to access the file.

我试图保存到一个文件中的数据是HTML。

The data i'm trying to save to a file is html.

如何才能做到这一点?

推荐答案

(假设你的意思如何将一个文件的内容复制到内存流)

(Presuming you mean how to copy a file's content to a memory stream)

如果您使用的是框架4:

If you are using framework 4:

     MemoryStream memoryStream = new MemoryStream();
     using (FileStream fileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read))
     {
       fileStream.CopyTo(memoryStream);
     }

这篇关于创建文件并使用的MemoryStream保存到它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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