非常困惑,当我用下面的代码读取文件时,它打印出FFFFFF,任何人都可以向我解释这个文本文件只有数字和字母在里面?任何帮助将是最伟大的!C#在文件中使用十六进制打印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);
}
你确定*它只有字母和数字吗?它可能还有线返回,空格和EOF标记。 – mellamokb 2011-05-16 18:52:43
该文件的编码是什么?你确定你的'StreamReader'使用相同的编码吗? – Oded 2011-05-16 18:55:26
你提到它打印出FFFFFF。你的意思是字面意思吗?按照您的预期,文件中的字符与F中的字符的比例是2:1吗?每个'MessageBox.Show(s);'调用都显示一个带FF的消息框吗? – Tim 2011-05-16 18:59:32