开发者

Java 1.6 abstracted random access

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 开发者_StackOverflowis 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.)


This is what Java NIO is for.

See Random Access Files and Memory-mapped files.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜