← Quiz: File Handling in Java: all 10 questions
Quiz: File Handling in Java · Question 7 of 10
You write lines with a BufferedWriter but never close or flush it. What can happen?
You write lines with a BufferedWriter but never close or flush it. What can happen?
- A.Nothing; data is written immediately
- B.The program does not compile
- C.The last lines may stay in the buffer and never reach the file
- D.The file is deleted
Answer & explanation
Correct answer: The last lines may stay in the buffer and never reach the file
Data reaches the file when the buffer fills, or on flush/close. Try-with-resources closes it for you.
Can you get the rest right without peeking?
Take the timed Quiz: File Handling in Java quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →