Java OCA OCP Practice Question 180

Question

Suppose you want to read a file that was not created by a Java program.

The file contains lines of 8-bit text, and the 8-bit encoding represents the local character set, as represented by the current default locale.

The lines are separated by newline characters.

Which strategy reads the file and produces Java strings?

  • A. Create a RandomAccessFile instance and use its readText() method.
  • B. Create a RandomAccessFile instance and use its readUTF() method.
  • C. Create a FileReader instance. Pass it into the constructor of LineNumberReader. Use LineNumberReader's readLine() method.
  • D. Create a FileInputStream instance. Pass it into the constructor of LineNumberReader. Use LineNumberReader's readLine() method.
  • E. Create a FileInputStream instance. Pass it into the constructor of DataInputStream. Use DataInputStream's readLine() method.


C.

Note

For a file that contains only 8-bit text, use a reader.

By default, a reader interprets 8-bit text according to the current default locale.

Readers read their input character by character; to assemble the characters into lines of text, chain on a LineNumberReader and call its readLine() method.




PreviousNext

Related