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.


public class Sample {
   public static void main(String args[]) throws Exception {
      File file = new File("myFile");
      FileInputStream fis = new FileInputStream(file);


Exception in thread "main" myFile
(The system cannot find the file specified)
      at Method)
      at Source)
      at<init>(Unknown Source)
      at a5Exception_Handling.NullPointer.main(
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know