用户登录
用户注册

分享至

将字节数组保存到文件

  • 作者: 想念你的腿想念你的嘴
  • 来源: 51数据库
  • 2022-12-15

问题描述

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.

解决方案

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

软件
前端设计
程序设计
Java相关