45.3k views
3 votes
If the IOData.dat file does not exist, what will happen when the following statement is executed? RandomAccessFile randomFile = new RandomAccessFile("IOData.dat", "rw");

User TrtG
by
7.5k points

1 Answer

5 votes

Answer:

Creates the file with the given file name.

Step-by-step explanation:

  • Here, the constructor is RandomAccessFile randomFile = new RandomAccessFile("IOData.dat", "rw");
  • The general form to construct the object of RandomAccessFile class is RandomAccessFile randomFile = new RandomAccessFile(String Filename, String mode);
  • Here, the String Filename is the filename of the file that has to executed with the String mode.
  • The modes decide the accessibility of the file, types like r - 'read only' the file , rw - 'read and write' the file. If the file doesn't exists it creates the file with the given filename.
  • If a file with read only mode is tried to write in the file, then it throws exceptions.
User Gabriella Giordano
by
7.6k points