Taming the file-reading tightrope act

Report a typo

Fill in the blanks in the given code to create a method that reads a file and handles exceptions. What exceptions should be caught, and how can you ensure the file is properly closed after reading?

Fill in the gaps with the relevant elements
public static void radFile(String ) {
     (  ((fileName))) {
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
    }  ( e) {
        System.out.println("File not found: " + e.getMessage());
    } catch ( e) {
        System.out.println("Error reading file: " + e.getMessage());
    }
}
fileNamenew FileReadercatchereaderIOExceptionFileNotFoundException= new BufferedReaderBufferedReadertry
___

Create a free account to access the full topic