What is the result, if the file salesreport.dat does not exist?

Given the code fragment: What is the result, if the file salesreport.dat does not exist?

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



Leave a Reply 4

Your email address will not be published. Required fields are marked *


duff

duff

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();
}
}

gelete

gelete

you are not using the try-with-resources

Babak

Babak

E
resources in try with resource are final.

gelete

gelete

E

Compilation fails at line 13:
The resource br of a try-with-resources statement cannot be assigned