← Quiz: File Handling in Java: all 10 questions
Quiz: File Handling in Java · Question 8 of 10
Why must Files.lines(path) be used inside try-with-resources?
Why must Files.lines(path) be used inside try-with-resources?
- A.The stream keeps the file open until it is closed
- B.It returns null otherwise
- C.It is required for all streams in Java
- D.Otherwise it reads the file twice
Answer & explanation
Correct answer: The stream keeps the file open until it is closed
Files.lines reads lazily from an open file. Closing the stream releases the file handle.
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 →