nerdexam
Oracle

1Z0-804 · Question #60

Which code fragment correctly appends "Java 7" to the end of the file /tmp/msg.txt?

The correct answer is B. FileWriter w = new FileWriter("/tmp/msg.txt", true). FileWriter(File file, boolean append) A: clears the file and append "Java7" Constructs a FileWriter object given a File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning.Parameters: file - a File object to write…

Java I/O Fundamentals

Question

Which code fragment correctly appends "Java 7" to the end of the file /tmp/msg.txt?

Options

  • AFileWriter w = new FileWriter("/tmp/msg.txt");
  • BFileWriter w = new FileWriter("/tmp/msg.txt", true);
  • CFileWriter w = new FileWriter("/tmp/msg.txt", FileWriter.MODE_APPEND);
  • DFileWriter w = new FileWriter("/tmp/msg.txt", Writer.MODE_APPEND);

How the community answered

(22 responses)
  • A
    9% (2)
  • B
    82% (18)
  • C
    5% (1)
  • D
    5% (1)

Explanation

FileWriter(File file, boolean append) A: clears the file and append "Java7" Constructs a FileWriter object given a File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning.Parameters: file - a File object to write toappend - if true, then bytes will be written to the end of the file rather than the beginning

Topics

#FileWriter#append mode#file I/O

Community Discussion

No community discussion yet for this question.

Full 1Z0-804 Practice