Throwing the FileNotFoundException - Java Object Oriented Design

Java examples for Object Oriented Design:Exception

Introduction

Here's the openFile method with the throws clause added:

Demo Code

import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class Main {
  public static void main(String[] args)
  {//from   w w  w  .ja  v  a  2 s.c  o  m
        try
        {
             openFile("C:/test.txt");
        }
        catch (FileNotFoundException e)
        {
             System.out.println("File not found.");
        }
  }

  public static void openFile(String name) throws FileNotFoundException {
     FileInputStream f = new FileInputStream(name);
  }
}

Related Tutorials