~/ learn/ comp-308/ cards/ finally, try-with-resources & multi-catch
1 of 6

try-with-resources auto-closes the reader

try-with-resources auto-closes the reader

Answer

try (BufferedReader in = new BufferedReader(new FileReader("examples1.txt"))) { System.out.println(in.readLine()); }

The reader implements `AutoCloseable`, so `in.close()` is called automatically when the block ends — even if `readLine()` throws.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/4921f4ce-0cf6-45be-82ed-9433d4ccdf22/flashcard utf-8 LF