 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to capture file not found exception in Java?
While using FileInputStream, FileOutputStream, and RandomAccessFile classes, we need to pass the path of the file to their constructors. In case of a file in the specified path does not exist a FileNotFoundException is raised.
Example
public class Sample {    public static void main(String args[]) throws Exception {       File file = new File("myFile");       FileInputStream fis = new FileInputStream(file);       System.out.println("Hello");    } }  Output
Exception in thread "main" java.io.FileNotFoundException: myFile (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.open(Unknown Source) at java.io.FileInputStream.<init>(Unknown Source) at a5Exception_Handling.NullPointer.main(NullPointer.java:10)
Advertisements
 