二进制文件读取问题

jin_ok 2008-05-06 06:18:53
现在有文件名,读取这个文件,要求返回byte数组
...全文
54 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
simple870617 2008-05-06
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 baihe_591 的回复:]
C# code
FileStream Mystream=new FileStream("MyBinary.dat",FileMode.Open,FileAccess.Read);
BinaryReader MyReader=new BinaryReader(Mystream);
byte[] myfile=new byte[Mystream.length];
MyReader.Read(myfile,0,myfile.length);
myReader.Close();
Mystream.Close();
[/Quote]

gang6556934 2008-05-06
  • 打赏
  • 举报
回复
跟着学习!
baihe_591 2008-05-06
  • 打赏
  • 举报
回复

FileStream Mystream=new FileStream("MyBinary.dat",FileMode.Open,FileAccess.Read);
BinaryReader MyReader=new BinaryReader(Mystream);
byte[] myfile=new byte[Mystream.length];
MyReader.Read(myfile,0,myfile.length);
myReader.Close();
Mystream.Close();
viena 2008-05-06
  • 打赏
  • 举报
回复
using System.IO;
viena 2008-05-06
  • 打赏
  • 举报
回复
string path = @"C:\Temp.dat";
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
int len = (int)fs.Length;
byte[] buffer = new byte[len];
fs.Read(buffer, 0, len);
fs.Close();
277894613 2008-05-06
  • 打赏
  • 举报
回复

System.IO.BinaryReader reader = null;
try
{
new System.IO.BinaryReader(System.IO.File.Open("filename", System.IO.FileMode.Open, System.IO.FileAccess.Read), System.Text.Encoding.GetEncoding("your encoding"));
byte[] buf = reader.ReadBytes((int)reader.BaseStream.Length);
}
finally
{
reader.Close();
}

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧