RandomAccessFile encapsulates a random-access file..It is not derived from Inputstream or OutputStream. Instead, it implements the interfaces Datainput and DataOutput, which define the basic I/O methods. It also supports positioning requests-that is, you can position the file pointer within the file. It has these two constructors:
RandomAccessFile(File fileObj, String access)
RandomAccessFile(String Jilenil11re, String. access)
RandomAccessFile implements the standard input and output methods, which you can use to read and write to random access file. There is, however one new method added by Java 2: setLength( ).It has this signature:
void setLength(long len) throws IOException .
This method sets the length of the invkiflg fiic to that specified by lell.This method can be used to lengthen or 'shorten it file. If the file is lengthened, the added0 portaluri is undefined.
The Character Streams
While the byte stream classes provide-sufficient functionality to handle any type of 1/0 operation, they cannot work directly with Unicode characters. Since one of the main purposes of Java is to support the write once, run anywhere" philosophy; it was necessary to include. direct I/O support for characters. In this section; several of the. character I/O classes are discussed. As explained earlier, at the top 'of the character stream hierarchies are .Reader and Writer abstract classes. We will begin with them.
As discussed in Chapter 12, the character the 1.1 release of Java. Because of this, you may still find legacY code flint uscs lafIte stria where I . xhamster streams could be. When working on,such' cOde~if is n 'good idM to update it.
Reader is an abstract class that defines Java's model of streaming. All of the methods in·this class will throw an IOException on error conditions provides a synopsis of the methods in Reader.