Handling IOException Example
This program demonstrates handling IOException.
Problem Statement
Write a Java program that handles IO errors during file operations.
Source Code
| 1 | import java.io.*; |
| 2 | public class IOExceptionExample { |
| 3 | public static void main(String[] args) { |
| 4 | System.out.println("Eduinq IOException Example"); |
| 5 | try { |
| 6 | FileReader fr=new FileReader("missing.txt"); |
| 7 | BufferedReader br=new BufferedReader(fr); |
| 8 | System.out.println("Eduinq File Content: "+br.readLine()); |
| 9 | } catch(IOException e) { |
| 10 | System.out.println("Eduinq Exception: IO Error - "+e.getMessage()); |
| 11 | } |
| 12 | } |
| 13 | } |
Program Output
Eduinq IOException Example Eduinq Exception: IO Error - missing.txt (No such file or directory)
Explanation
IOException occurs during input/output operations like file reading. - Try-catch ensures program continues gracefully even if file is missing. - This design improves reliability and error reporting. - In enterprise systems, IO exception handling ensures stable data access and processing. Conclusion: Shows handling of IOException in file operations.