读取16进制文件的问题

caterpillar12345 2010-09-17 03:10:13
在一个tab文件里,存了一些整数,有ushort类型的a,byte类型的b,都是以16进制存放的。
怎样才能读出位于最后面的b变量???
...全文
104 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gomoku 2010-09-17
  • 打赏
  • 举报
回复
另外一种写法:
using(FileStream fs = new FileStream("...", FileMode.Open))
using(BinaryReader br = new BinaryReader(fs))
{
br.BaseStream.Seek(- sizeof(short), SeekOrigin.End);
short s = br.ReadSingle();
}
caterpillar12345 2010-09-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 gomoku 的回复:]
C# code
using(FileStream fs = new FileStream("...", FileMode.Open))
{
fs.Seek(-1, SeekOrigin.End);
int b = fs.ReadByte();
}
[/Quote]

这个方法挺好的,但是如果最后一个变量不是占一个字节呢?要怎么取出来。。
caterpillar12345 2010-09-17
  • 打赏
  • 举报
回复
就是有一个tab文件
里面每一行都是按 abcdefg。。。x 等等 这样排列的,其中有ushort类型的,还有byte类型的,都是以16进制的形式存放的
现在我想把最后一个变量 x 给读出来

就是这个意思。。。
yangjinCK 2010-09-17
  • 打赏
  • 举报
回复
不太明白你想说什么
gomoku 2010-09-17
  • 打赏
  • 举报
回复
using(FileStream fs = new FileStream("...", FileMode.Open))
{
fs.Seek(-1, SeekOrigin.End);
int b = fs.ReadByte();
}

110,534

社区成员

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

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

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