文件&字节流转换

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

FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);

byte[] bytesRead = new byte[(int)fs.Length];

fs.Read(bytesRead, 0, bytesRead.Length);

fs.Close();

return bytesRead;

2、将字节流写入文件

byte[] bytesWrite = ….

FileStream fs = new FileStream(“xxx”,FileMode.Create, FileAccess.Write);

fs.Write(bytesWrite, 0, bytesWrite.Length);

fs.Close();

posted @ 2009-09-22 09:17  pursue  阅读(902)  评论(0编辑  收藏  举报