向后读取二进制文件

发布于 2024-10-15 07:23:11 字数 527 浏览 3 评论 0原文

我需要做的是向后读取文件。我想要做的是向后读取文件,然后按原样向后移动查看值是否 = G 或十六进制 47,然后查看下一个值是否 = N 或十六进制 4E,然后查看下一个值是否 = P 。我目前正在使用二进制 IO 来读入,然后使用...

这是一个图像链接,可以更好地展示我的意思.. http://www.facebook.com/photo.php?pid=2189508&l=92393dfccb&id=1283154964

  String s = Integer.toHexString(hexIn);
  if(s.length() < 2){
   s = "0" + Integer.toHexString(hexIn);
  }

为了确保十六进制不会错过末尾的任何零(我在这个网站上找到的::)

What I need to do is read in a file backwards. What I would like to be able to do is read the file backwards then as is moves backwards see if the value = G or in hex 47 then see if the next value = N or in hex 4E and then see if the next value = P. I'm currently using the binary IO to read in and then using...

Here is a link to an image which will better show what I mean.. http://www.facebook.com/photo.php?pid=2189508&l=92393dfccb&id=1283154964

  String s = Integer.toHexString(hexIn);
  if(s.length() < 2){
   s = "0" + Integer.toHexString(hexIn);
  }

To make sure the hex does not miss any zeros on the end (which I found on this site::)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

浅忆 2024-10-22 07:23:11

与其向后读取文件并查找字符串,为什么不直接反转字符串并在向前的文件中查找它呢?这似乎是一个更简单的解决方案?

Rather than read the file in backwards and look for your string, why don't you just reverse your string and look for it in the file going forwards? That would seem to be an easier solution?

浮生面具三千个 2024-10-22 07:23:11

正如你可以想象的那样,向后阅读并不是一件正常的事情,你必须做一些奇怪的事情。

但是您可以自己将索引放入文件中。如果你这样做,将其放在末尾,读取一个字节,然后将其放在 (end-1),读取一个字节,依此类推,你就会成功。

这会非常慢,所以你要做的就是从末尾开始将尽可能多的内容读入缓冲区,然后向后遍历缓冲区,然后重新填充缓冲区。

本教程告诉您有关 Java 中随机访问 I/O 的所有信息。

As you can imagine, reading backwards isn't the normal thing, and you'll have to do something weird.

But you can place the index into the file yourself. If you did that, placed it at the end, read a byte, then placed it at (end-1), read a byte, and so on, you'd succeed.

It would be horribly slow, so what you do iss read as much as you can into a buffer, starting at the end, then go through the buffer backward, then refill the buffer.

This tutorial tells you all about random access I/O in Java.

↘紸啶 2024-10-22 07:23:11

RandomAccessFile 将是用于向后读取文件的最简单的类。

RandomAccessFile would be the easiest class to use to read a file backwards.

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