【问题标题】:How to Read from a Section of a File?如何读取文件的一部分?
【发布时间】:2014-03-02 21:38:03
【问题描述】:

我正在尝试读取此文件的一部分,该部分在从 Xbox 转储时存储了有效负载。

我要做的是从有效负载所在的位置读取,如果它等于所有 0's,然后将标签更改为No

我知道我可能应该使用BinaryReader,但我没有太多经验。 有效载荷从0x32500 开始,到0x3256F 结束。

我在 C# 中需要这个。

【问题讨论】:

    标签: c# binaryreader


    【解决方案1】:

    通过Seek 方法读取时可以快进流。然后使用BinaryReaderReadBytes 方法从该偏移量读取字节。

    using (var br = new BinaryReader(stream)) {
        br.BaseStream.Seek(0x32500, SeekOrigin.Begin);
        var bytes = br.ReadBytes(0x3256F - 0x32500);
    
        if (bytes.All(x => x == 0)) {
            label.Text = "No";
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-18
      • 2016-08-09
      • 2015-05-17
      • 2012-05-28
      • 1970-01-01
      • 1970-01-01
      • 2019-09-09
      相关资源
      最近更新 更多