try-with-resources Statement

static String readFirstLineFromFile(String path) throws IOException {
    try (BufferedReader br = new BufferedReader(new FileReader(path))) {
        return br.readLine();
    }
}

When the block of code terminates, either normally or because of an exception, the close methods of the Closable objects are automatically called. Note that the close methods of resources are called in the opposite order of their creation.

More info here.