Random Access IO Stream


Random Access IO Stream

Random Access IO Stream:
Random Access IO Stream lets us perform read and write operation using a single Streaming Object. Random Access IO Stream also provides an API to move around the File Pointer (seek() API call). Example of Random Access IO Stream is ‘RandomAccessFile’.



A RandomAccessFile stream is created as follows



//"r" -- Open for reading only. Invoking any of the write methods of the resulting object will cause an IOException to be thrown.
//"rw" -- Open for reading and writing. If the file does not already exist then an attempt will be made to create it.
//"rws" -- Open for reading and writing, as with "rw", and also require that every update to the file's content or metadata be written synchronously to the //underlying storage device.
//"rwd" -- Open for reading and writing, as with "rw", and also require that every update to the file's content be written synchronously to the underlying //storage device.
RandomAccessFile randomAccessFile = new RandomAccessFile("randomaccessfile.txt", "rw");


RandomAccessFile Stream provides us with an API to point the File Pointer to a specific location in the File.


int fileLocation = 10;
// Moving the File pointer to the designated location.
randomAccessFile.seek(fileLocation);
<< Sequence IO Stream

No comments:

Post a Comment