Home » Oracle » 1z0-804 » Which code fragment correctly appends “Java 7” to the end of the file /tmp/msg.txt?
Which code fragment correctly appends "Java 7" to the end of the file /tmp/msg.txt?
A. FileWriter w = new FileWriter("/tmp/msg.txt"); append("Java 7"); close();
B. FileWriter w = new FileWriter("/tmp/msg.txt", true); append("Java 7"); close();
C. FileWriter w = new FileWriter("/tmp/msg.txt", FileWriter.MODE_APPEND); append("Java 7"); close();
D. FileWriter w = new FileWriter("/tmp/msg.txt", Writer.MODE_APPEND); append("Java 7"); close();
Correct Answer: B
Explanation/Reference:
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 to append – if true, then bytes will be written to the end of the file rather than the beginning
Download Printable PDF. VALID exam to help you PASS.
|
|