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 write data to a file in the BasicFileOutput example?

  1. FileWriter

  2. BufferedWriter

  3. PrintWriter

  4. FileOutputStream

The correct answer is: PrintWriter

The PrintWriter class is used to write data to a file in the BasicFileOutput example because it provides convenient methods for writing various types of data to a file. A FileWriter is used for writing character streams while a FileOutputStream is used for writing bytes. A BufferedWriter is used to buffer output and improve efficiency, but it does not directly write data to a file. Therefore, the correct answer is C because it specifically allows for writing data to a file in a convenient and efficient manner.