Type a try-with-resources file-reading loop
Type a try-with-resources file-reading loop
Answer
try (BufferedReader br = new BufferedReader(new FileReader("f.txt"))) { String line; while ((line = br.readLine()) != null) { System.out.println(line); } }
readLine returns null (not an exception) at EOF. The loop condition assigns and tests in one step. br.close() is called regardless of outcome.