从二进制文件读取数据 [英] reading data from binary file

查看:191
本文介绍了从二进制文件读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我必须从特定位置0 * FFF0的二进制文件中读取数据,然后使用c#将数据存储到变量中.二进制文件被作为输入给出.

谁能帮我一个忙????

Hi All,

I have to read data from a binary file at a specific location 0*FFF0 and store the data into a variable using c# .The binary file is being given as input .

Can anyone help me out ?????

推荐答案

您可以尝试使用文件流. Seek()到要从其开始的位置,然后Read()所需的字节.

您提到只需要一个字节.为此,将更新代码.

You could try using a file stream. Seek() to the position you want to start from and then Read() the bytes you need.

You mentioned to need only one byte. The code is updated for that need.

using (System.IO.FileStream stream = new System.IO.FileStream(filepath, System.IO.FileMode.Open))
{
    int startIndex = 0xFFF0;

    stream.Seek( startIndex);
    byte data = stream.ReadByte();

    stream.Close();
}

当然,错误处理留给实现者.

Error handling is left to the implementer, of course.


这篇关于从二进制文件读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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