将字节数组写入磁盘 [英] Writing Byte Array to Disk

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

问题描述

我有代码允许我将

字节数组的内容呈现给屏幕,但我需要将内容写入磁盘。建议?


谢谢

解决方案

10月1日下午6:11,Garth Wells < nob ... @ nowhere.comwrote:


我有代码允许我渲染

的内容字节数组到屏幕,但我需要将内容写入磁盘。建议?


谢谢



FileStream.Write(...)?


确定。只需将其写入磁盘即可。 :)


//创建1 MB数组,并填充随机内容

var b =新字节[1024 * 1024];

(new Random())。NextBytes(b);


//将数组写入磁盘

using(var f = File.Open (foo.bin,FileMode.CreateNew))

f.Write(b,0,b.Length);


(我是'我已经沉迷于C#3语法...我真的很喜欢''var'')


-

Chris Mullins


" Garth Wells" < no **** @ nowhere.comwrote in message

news:ef ************** @ TK2MSFTNGP03.phx.gbl ...


我有代码允许我将

字节数组的内容呈现给屏幕,但我需要编写内容

到磁盘。建议?


谢谢



Garth Wells< no **** @ nowhere。编写:


我有代码允许我将

字节数组的内容呈现给屏幕,但我需要将内容

写入磁盘。建议?



使用FileStream,并在其上调用Write。


-

Jon Skeet - < sk *** @ pobox.com>
http:// www .pobox.com / ~silet 博客: http://www.msmvps .com / jon.skeet

如果回复小组,请不要给我发邮件


I''ve got code that allows me to render the contents of a
byte array to the screen, but I need to write the contents
to disk. Suggestions?

Thanks

解决方案

On Oct 1, 6:11 pm, "Garth Wells" <nob...@nowhere.comwrote:

I''ve got code that allows me to render the contents of a
byte array to the screen, but I need to write the contents
to disk. Suggestions?

Thanks

FileStream.Write(...)?


Sure. Just write it to the disk. :)

// Create a 1 MB array, and fill with random stuff
var b = new byte[1024 * 1024];
(new Random()).NextBytes(b);

// Write array to disk
using (var f = File.Open("foo.bin", FileMode.CreateNew))
f.Write(b, 0, b.Length);

(I''m already addicted to the C# 3 syntax... I really like ''var'')

--
Chris Mullins

"Garth Wells" <no****@nowhere.comwrote in message
news:ef**************@TK2MSFTNGP03.phx.gbl...

I''ve got code that allows me to render the contents of a
byte array to the screen, but I need to write the contents
to disk. Suggestions?

Thanks



Garth Wells <no****@nowhere.comwrote:

I''ve got code that allows me to render the contents of a
byte array to the screen, but I need to write the contents
to disk. Suggestions?

Use a FileStream, and call Write on it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


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

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