C#读取二进制文件
嘿嘿本人巨菜,我想用二进制的方式读取一个文件,如图,65~68字节,然后再倒过来组装一下12234929最后再转成十进制304302377
谢谢,初学C#数据类型转换头都大了,还是弄不出来!_!
补充:嘿嘿研究出来了System.IO.FileInfo f = new FileInfo(qqpath+"LoginUinList.dat");
int flen=(Int32)f.Length;
byte[] byData = new byte[flen];
Int32[] asQQID = new Int32[flen];FileStream sFile = new FileStream(qqpath + "LoginUinList.dat", FileMode.Open);
sFile.Read(byData, 0, flen);string alldata;
int fpos=0;
int i =0;while (fpos<flen -40)
{
if (Convert.ToString((long)byData[fpos], 16) == "51")
{
if (Convert.ToString((long)byData[fpos + 1], 16) == "44")
{
alldata = "";alldata = alldata + Convert.ToString((long)byData[fpos + 54], 16);
alldata = alldata + Convert.ToString((long)byData[fpos + 53], 16);
alldata = alldata + Convert.ToString((long)byData[fpos + 52], 16);
alldata = alldata + Convert.ToString((long)byData[fpos + 51], 16);asQQID[i] = Convert.ToInt32(alldata, 16);
i++;
fpos += 54;
}
else
{
fpos++;
}
}
else
{
fpos++;
}
}方法肯定有点笨,逐字节逐字节的去比较,用来解析2008版QQ登陆号码用的
追问:我是要用C#去读取本机的文件比如“test.txt”截图是我用Notepad++编辑器看到的