(java: method and text files): consider the following code snippet: PrintWriter
ID: 3623995 • Letter: #
Question
(java: method and text files): consider the following code snippet:PrintWriter out = new PrintWriter("output.txt");
Which of the following statements about the PrintWriter object is correct?
a. If a file named "output.txt" already exists, an exception will occur.
b. If a file named "output.txt" already exists, data will be added at the end of the file.
c. If a file named "output.txt" already exists, existing data will be deleted before data
is added to the file.
d. If a file named "output.txt" already exists, a new file named "output_1.txt" will be
created and used.
Explanation / Answer
a: No (Only If the file is write-protected) b. No (PrintWriter overwrites existing data) c. Yes (PrintWriter overwrites existing data) d. No (Unless you specifically checks for existing files and renames new file accordingly)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.