Java 1.6 抽象随机访问

发布于 2024-08-16 21:01:15 字数 104 浏览 14 评论 0原文

作为 Java 专家,您建议如何抽象随机访问,以便代码可以不知道其访问的数据是在内存中还是在硬盘驱动器上的文件中?

(相关文件的大小可能有几千兆字节。随机访问是最重要的功能。)

As a java guru, what would you suggest to abstract random access so that a code can be agnostic to whether the data its accessing is in memory or in a file on the harddrive?

(The files in question could be several gigabytes in size. Having random access is the most important feature.)

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

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

发布评论

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

评论(2

苏璃陌 2024-08-23 21:01:15

这就是 Java NIO 的用途。

请参阅随机访问文件内存映射文件

This is what Java NIO is for.

See Random Access Files and Memory-mapped files.

轮廓§ 2024-08-23 21:01:15

我可以提供文件的内存映射。这些给你一个java.nio.ByteBuffer。你也可以将它们作为普通的内存对象,所以你就可以实现完美的无知,即使不是完全的无知。

我们从 1.4。

这个问题在某些方面尚不清楚。如果您想要文件式访问,那么您就不太走运了,因为无法在任何内存资源上构造 RandomAccessFile。

I can offer memory mapping of files. Those give you a java.nio.ByteBuffer. And you can also make those as ordinary in-memory objects, so there you go, perfect agnosis, if not perfect ignorance.

And we've had them since 1.4.

The question is in some respects unclear. If you want file-style access, you are rather out of luck, since a RandomAccessFile can't be constructed over any in-memory resource.

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