软件编程
位置:首页>> 软件编程>> C#编程>> C#文件和字节流的转换方法

C#文件和字节流的转换方法

作者:永远爱好写程序  发布时间:2022-03-18 05:39:43 

标签:C#,文件,字节流

本文实例讲述了C#文件和字节流的转换方法。分享给大家供大家参考。具体实现方法如下:

1、读取文件,并转换为字节流


FileStream fs = new FileStream(filename,FileMode.Open,FileAccess.Read);
byte[] infbytes = new byte[(int)fs.Length];
fs.Read(infbytes, 0, infbytes.Length);
fs.Close();
return infbytes;

2、将字节流写入文件


FileStream fs = new FileStream("D:\inf.dlv",FileMode.Create,FileAccess.Write);
fs.Write(infbytes, 0, inf.Length);
fs.Close();

希望本文所述对大家的C#程序设计有所帮助。

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com