What is the correct way to close a file in Java after writing to it?
2024
What is the correct way to close a file in Java after writing to it?
- A.
fileInput.close();
- B.
file.close();
- C.
fileWriter.close();
- D.
fileStream.close();
- E.
Question not attempted
Attempted by 85 students.
Show answer & explanation
Correct answer: C
When a FileWriter object is used for writing, calling fileWriter.close() closes the writer and releases the file resource.