Save byte array to file [duplicate]

2019-02-01 19:50发布

This question already has an answer here:

I have a byte array (an IEnumerable actually), and I need to save it to a new file containing this data.

How do I do that?

I found some answers telling how to create a MemoryStream from that, but still can't save it to a brand new file.

2条回答
叛逆
2楼-- · 2019-02-01 20:23

You can use:

File.WriteAllBytes("Foo.txt", arrBytes); // Requires System.IO

If you have an enumerable and not an array, you can use:

File.WriteAllBytes("Foo.txt", arrBytes.ToArray()); // Requires System.Linq
查看更多
来,给爷笑一个
3楼-- · 2019-02-01 20:40
登录 后发表回答