Given the code fragment: What is the result, if the file salesreport.dat does not exist?
A.
Class java.io.FileNotFoundException
B.
Class java.io.IOException
C.
Compilation fails at line 6 and 13
D.
Compilation fails only at line 6
E.
Compilation fails only at line 13
A.
Tested with code:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class displayDetailsTest {
public static void displayDetails() {
try {
BufferedReader br = new BufferedReader(new FileReader(“salesreader.dat”));
String record;
while ((record = br.readLine()) != null) {
System.out.println(record);
}
br.close();
br = new BufferedReader(new FileReader(“annualreader.dat”));
while ((record = br.readLine()) != null) {
System.out.println(record);
}
} catch (IOException ex) {
System.err.println(ex.getClass());
}
}
public static void main(String[] args) {
displayDetails();
}
}
you are not using the try-with-resources
E
resources in try with resource are final.
E
Compilation fails at line 13:
The resource br of a try-with-resources statement cannot be assigned