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?
Exception handling
Taming the file-reading tightrope act
Report a typo
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());
}
} ___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.