try-with-resources
A try statement that declares resources in brackets and closes each one automatically, on every path.
try (R r = ...) { ... } calls close() once per resource when the block ends, in reverse order of opening and before any catch or finally runs (Java 7; existing effectively final variables since Java 9).
Examples
try (var reader = Files.newBufferedReader(path)) { ... }closes the reader however the block ends.
See also