保存字节数组到文件 [英] Save byte array to file

查看:195
本文介绍了保存字节数组到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字节数组(一个IEnumerable实际上),我需要将其保存到包含此数据的新文件。

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

我该怎么办呢?

我找到了一些答案,告诉如何创建从一个MemoryStream,但仍然无法将其保存到一个全新的文件。

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

推荐答案

您可以使用:

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

这篇关于保存字节数组到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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