🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.The stream keeps the file open until it is closed
  2. B.It returns null otherwise
  3. C.It is required for all streams in Java
  4. 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 →