‹ Back to the paper
What is the difference between the following two statements? 1. `FileWriter fw = new…
What is the difference between the following two statements?
1. `FileWriter fw = new FileWriter(<file name>);`
2. `FileWriter fw = new FileWriter(<file name>, true);`
Answer
Answer
AIFileWriter fw = new FileWriter(<file name>); opens the file for writing and, if the file already exists, erases (overwrites) its existing content before writing.
FileWriter fw = new FileWriter(<file name>, true); opens the file in append mode: the existing content is kept, and new data is written starting after the end of the file.
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 59.