UNB/ CS/ David Bremner/ teaching/ java/ TryFinally.java
import java.io.*;

public class TryFinally{

  static void main(String[] args){
    
    int tries=0;
    boolean done=false;
    FileReader inFile=null;

    BufferedReader console=
      new BufferedReader(
                 new InputStreamReader(System.in));

    while(!done){
      try{
        System.out.println("Please enter a file name:");

        String name=console.readLine();
        inFile=new FileReader(name);
        done=true;
        
      }
      catch(FileNotFoundException fnf){
        System.out.println(fnf.toString());
      }
      catch(IOException oops){
        System.out.println(oops.toString()+". Exiting");
        System.exit(1);
      }
      finally{
        tries++;
      } // try, catch, finally
    } // while

    System.out.print("Congratulations, it only took you " + tries );
    if (tries == 1 )
      System.out.println("try");
    else System.out.println(" tries.");
  }
}