C# 使用十六进制读取文件打印 FFFFFF

发布于 2024-11-07 10:21:42 字数 673 浏览 0 评论 0原文

对此感到非常困惑,当我使用下面的代码读取文件时,当它到达末尾时,它会打印出 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

趴在窗边数星星i 2024-11-14 10:21:43

每个循环迭代有 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 one Read call? And why aren't you reading a block at a time?

内心旳酸楚 2024-11-14 10:21:43

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文