Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


Which class is used to create a memory-mapped file for reading and writing?

  1. FileInputStream

  2. RandomAccessFile

  3. MappedByteBuffer

  4. FileChannel

The correct answer is: RandomAccessFile

RandomAccessFile is the correct answer because it is specifically designed for reading and writing files and provides methods for accessing any part of the file. FileInputStream is used for only reading and does not allow for writing to the file. MappedByteBuffer is used for mapping a specific portion of a file to memory and is not used for creating a file. FileChannel does not create a file but is used for reading, writing, and manipulating files. Therefore, RandomAccessFile is the best choice for creating a memory-mapped file for reading and writing.