Randomaccessfile and NiO "memory-mapped Files" (memory-mapped file)

Source: Internet
Author: User

randomaccessfile the only parent class for Randomaccessfile is object, which is different from other stream parent classes. is used to access files that hold data records, so you can use the Seek () method to access the records and read and write them. The sizes of these records do not have to be the same, but their size and position must be knowable. Randomaccessfile unexpectedly will not belong to InputStream and OutputStream class system. In fact, in addition to implementing the Datainput and DataOutput interfaces (both DataInputStream and DataOutputStream implement both interfaces), it has nothing to do with these two classes, Not even the InputStream and OutputStream have been prepared to function; it is a completely independent class, and all methods (most of them belong to itself) are written from scratch. This may be because randomaccessfile can move back and forth within a file, so its behavior is fundamentally different from other I/O classes. In summary, it is a separate class that inherits directly from object. Basically, the way randomaccessfile works is to glue DataInputStream and dataoutputstream together, plus some of its own methods, such as positioning getfilepointer (), The Seek () to be moved in the file, and the length () of the file size to be judged. In addition, its constructor has a parameter that indicates whether to open the file as read-only ("R") or read-write ("RW") (fopen () of C). It does not support write-only files, from this point of view, if Randomaccessfile inherit the DataInputStream, it may do better. Only Randomaccessfile has a seek method, and this method applies only to files. Bufferedinputstream has a mark () method that you can use to set the tag (save the result in an internal variable), and then call Reset () to return to that position, but it is too weak and not practical.

Most of Randomaccessfile's features, if not all, have been superseded by NIO's "Memory Mapping Files" (memory-mappedfile).

NIO's "Memory-mapped file" (memory-mapped files)

Randomaccessfile and NiO "memory-mapped Files" (memory-mapped file)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.