Example: IOException

Single Choice
Views 25

Answer:


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.

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.