āœļø Explanatory Question

Example: IOException

šŸ‘ 30 Views
šŸ“˜ Detailed Answer
🟢 Easy
šŸ’”

Answer with Explanation


import java.io.FileReader;
import java.io.IOException;

public class CheckedExample {
    public static void main(String[] args) {
        try {
            FileReader file = new FileReader("non_existing_file.txt");
            file.read();
            file.close();
        } catch (IOException e) {
            System.out.println("File not found or cannot be read!");
        }
    }
}

šŸ“˜ Explanation:
The compiler forces you to handle IOException because the file may not exist or may not be readable.