One very important thing to note about the Random Access File class.It is very easy to seek past the end of the file and write to that location (as the Random Access File class assumes that one might wish to grow a file), however, if the file pointer is moved past the end of file and written to at that location, if the user tries to read it may encounter the End Of File or EOF at the old size and as such will throw an error. It will generate a file of a size 0 to 999 bytes and it will then fill those bytes in order with numbers from 65 to 90 (randomly chosen).Before reading this tutorial be sure to check the Random Access File API.Before getting started using the Random Access File class, be sure you understand the following concepts.As the comments explain, the read method returns an int representing how many bytes were actually read.After reading in the array, the program then outputs the position read started at, the amount of bytes read and the size of the array given to read.
Random Access File(File file, String mode) : Accepts file object and mode of read and write. "rwd" : Same as rw mode that also supports reduced number of IO operation.
In earlier tutorials we saw how we can use Java's scanner class to read sequential text files.
Scanners are great for reading files, but we can take a step farther out and conceptualize our data even more abstractly, instead of reading in files as strings we can instead read the raw bytes and then write those bytes to the file.
The real advantage is that once file is opened, it can be read from or written to in a random manner just by using a record number or you can add to the end since you will know how many records are in the file.
The Random Access File class allows us to jump to a certain location in the file by using the seek() method.