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 classes are recommended for file input and output in the given examples?

  1. BufferedInputStream and BufferedOutputStream

  2. FileReader and FileWriter

  3. FileInputStream and FileOutputStream

  4. DataInputStream and DataOutputStream

The correct answer is: FileReader and FileWriter

FileReader and FileWriter are recommended for file input and output because they are used for manipulating character files. BufferedInputStream and BufferedOutputStream are used to improve performance while reading and writing bytes from a file, but not specifically for handling character files like in the given examples. Similarly, FileInputStream and FileOutputStream are used for reading from and writing to binary files, not necessarily for character files. DataInputStream and DataOutputStream are used for reading primitive data types from a binary stream, not for file input and output. Therefore, FileReader and FileWriter are the most appropriate classes for file input and output in the given examples.