Tutorspoint provides Random Access Files Homework Help and assignment help for college and university students in USA, UK, Australia

Random Access Files

  • We have a class which allows opening a file in read-write mode so that we can perform the read and write operations using the same object. The class is Random Access File class.
  • Random Access File class supports all the functionalities using which we can read or write data from or into a file in the form of their primitive data types. Some of such functions are write Int (), write float () e. t. c.
  • Random Access File class has some functionality which supports the manipulation of file pointer.

Examples:

Seek (): moves the file pointer to a specific location

Length (): gives the length of the file.

Get file pointer (): gives the current location of file pointer.

Note:

Random Access File class is a byte oriented class. It reads or writes data internally in the form of bytes.

  • Constructor of Random Access File class is defined to accept two arguments.
  1. Name of the file – a string class object
  2. Mode – a starting class object

Mode:

Specifies whether the file has to be opened in the read mode (“ r “) or read/ write mode (“ rw”).

Uses of Random Access File class:

  • Whenever we need to store structured data in a file, then we use Random Access File class.
  • In olden days, Random Access File class was the key issue in developing the projects.
  • Even today, we use Random Access File class in some projects where we want to read the data from the files and store it into the database.

Note:

Whenever the constructor of a class is assumed to throw checked exceptions, then we can’t create object of the class directly at the place of declaring the instance variables, we define the references of that class as instance variables.

Read Records:

After all the records are entered into the file, then each record is read from the file and displayed on the screen. The logic is implemented in such a way that, while writing a record into the file, the file pointer will be at the end of file position. While reading the records, the file pointer points to the 0th location.

Random Access Files Homework Help