r/learnprogramming 16h ago

Question about Files.lines() with try-with-resources in Java

[deleted]

1 Upvotes

2 comments sorted by

1

u/andyflip 15h ago

If you wanted to be super explicit, you could release the resources in a finally {} after the catch.

2

u/GeorgeFranklyMathnet 16h ago

You're right to use try-with-resources on a file I/O stream, says Baeldung and other reliable sources.