

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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)
- Related Questions & Answers
- How to capture file not found exception in C#?
- How to capture divide by zero exception in Java?
- How to capture null reference exception in C#?
- How to capture and print Python exception message?
- How to capture divide by zero exception in C#?
- How to capture out of memory exception in C#?
- How to capture out of array index out of bounds exception in Java?
- How to capture index out of range exception in C#?
- How to resolve exception Element Not Interactable Exception in Selenium?
- How to capture an exception raised by a Python Regular expression?
- HTML file input control with capture and accept attributes is not working correctly
- Which exception is raised when an element is not found in an HTML DOM using XPath in Selenium?
- STR_TO_DATE as column, but column not found?
- How to check if a file exists or not in Java?
- How to create a user defined exception (custom exception) in java?
Advertisements