开发者

create file and save to it using memorystream

开发者 https://www.devze.com 2023-01-18 21:32 出处:网络
How can i create a file and write to it using the memory stream? I need to u开发者_StackOverflow中文版se the memorystream to prevent other threads from trying to access the file.

How can i create a file and write to it using the memory stream? I need to u开发者_StackOverflow中文版se the memorystream to prevent other threads from trying to access the file.

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

How can this be done?


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

If you are using framework 4:

var memoryStream = new MemoryStream();

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


Here are code to create file

byte[] data = System.Text.Encoding.ASCII.GetBytes("This is a sample string");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
ms.Write(data, 0, data.Length);
ms.Close();
0

精彩评论

暂无评论...
验证码 换一张
取 消