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)