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

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

Prepare for your Java exam with our ultimate quiz based on 'Thinking in Java'. Engage with expertly crafted questions that enhance your learning process. Perfect for Java enthusiasts looking to solidify their knowledge!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

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.