import java.io.FileReader;
import java.io.IOException;
public class ExceptionV8TryWithResources {
    public static void main(String args[]) {
        try (FileReader fr = new FileReader("file.txt")) {
            char[] a = new char[50];
            fr.read(a);   // reads the content to the array
            for (char c : a) {
                System.out.print(c);   // prints the characters one by one
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
/*
 * try-with-resources, also referred as automatic resource management, is a new
 * exception handling mechanism that was introduced in Java 7, which
 * automatically closes the resources used within the try catch block.
 *
 * To use this statement, you simply need to declare the required resources
 * within the parenthesis, and the created resource will be closed
 * automatically at the end of the block. Following is the syntax of
 * try-with-resources statement.
 */
 /*
 * Resource implements
 *   public interface AutoCloseable {...}
 * and the catch invokes its only method:
 *   void close() throws Exception;
 */
