Choose the correct option for this code snippet:
public static void main(String []files) { try (FileReader inputFile = new FileReader(new File(files[0]))) { // #1 inputFile.close(); // #2 } catch (FileNotFoundException | IOException e) { // #3 e.printStackTrace(); } }
d)
Both of the specified exceptions belong to the same hierarchy (FileNotFoundException derives from an IOException), so you cannot specify both exceptions together in the multi-catch handler block.
It is not a compiler error to explicitly call close()
method for a FileReader object inside a try-with-resources block.