C# 使用十六进制读取文件打印 FFFFFF
对此感到非常困惑,当我使用下面的代码读取文件时,当它到达末尾时,它会打印出 FFFFFF,任何人都可以向我解释一下,文本文件中只有数字和字母吗?任何帮助将是最伟大的!
String fileDirectory = "C:\\t.txt";
StreamReader reader = new StreamReader(fileDirectory);
int hexIn;
for (int i = 0; (hexIn = reader.Read()) != -1; i++)
{
String s;
s = hexIn.ToString("X2");
int x = 0;
while (x < 1)
{
hexIn = reader.Read();
s = hexIn.ToString("X2");
x++;
}
hexIn = reader.Read();
s = hexIn.ToString("X2");
MessageBox.Show(s);
}
very confused by this, when I read in a file using the code below when it gets to the end it prints out FFFFFF, could anyone explain this to me the text file only has numbers and letters in it? Any help would be most greatful!
String fileDirectory = "C:\\t.txt";
StreamReader reader = new StreamReader(fileDirectory);
int hexIn;
for (int i = 0; (hexIn = reader.Read()) != -1; i++)
{
String s;
s = hexIn.ToString("X2");
int x = 0;
while (x < 1)
{
hexIn = reader.Read();
s = hexIn.ToString("X2");
x++;
}
hexIn = reader.Read();
s = hexIn.ToString("X2");
MessageBox.Show(s);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个循环迭代有 3 个
Read
调用,这意味着其中任何一个调用都可以返回 -1 以指示文件结尾。我怀疑它会被转换为 FFFFFFFF,因此是你的输出。为什么有多个Read
调用?为什么你不一次读一个块呢?You've got three
Read
calls per loop iteration, which means that any one of them could return -1 to indicate the end of the file. I suspect that's then being converted to FFFFFFFF, hence your output. Why do you have more than oneRead
call? And why aren't you reading a block at a time?FFFFFF 也可以指示空值。如果你对任天堂 DS ROM 进行十六进制编辑,你会在末尾看到一大堆 FFFFFFFF ,这是因为游戏对于卡带来说太小了,所以实际上该文件末尾可能有空值。
The FFFFFF may also indicate an empty value. If you Hex editted Nintendo DS Roms you would see a whole bunch of FFFFFFFF at the end which is put there because the game is too small for the cartridge so in actual fact that file may have empty values at the end.