Type a try-with-resources opening a BufferedReader
Type a try-with-resources opening a BufferedReader
Answer
try (var br = new BufferedReader(new FileReader(path))) { String line; while ((line = br.readLine()) != null) { process(line); } }
br.close() is called automatically when the try block exits — whether normally or via exception. No finally block needed.