Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 59

2 marks

Computer ScienceISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024)DifferentiateObjects

Differentiate between the following.

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

FileWriter 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.