   import java.util.Scanner;
   import java.io.*;
/**
*
* This file shows what happens if you try to read from a closed file
* Note that the instantiation does not have to be in a try/catch block 
* if there is a file named input2.dat in the directory.  This is NOT
* something you should do in your programs.  
*
* @author Elizabeth Adams
*
*/
    public class TryToReadFromClosedFile
   {
       public static void main (String  [] args)throws FileNotFoundException
      {
         Scanner myFileScanner;
         String temp;
       
         myFileScanner = new Scanner (new File ("input2.dat"));
       
         temp = myFileScanner.nextLine();
         System.out.println (" picked up *"  + temp + "*");
         myFileScanner.close();
         temp = myFileScanner.nextLine(); /* this line causes 
        Exception in thread "main" java.lang.IllegalStateException: Scanner closed
            at java.util.Scanner.ensureOpen(Scanner.java:1025)
            at java.util.Scanner.findWithinHorizon(Scanner.java:1596)
      		at java.util.Scanner.findWithinHorizon(Scanner.java:1562)
      		at java.util.Scanner.nextLine(Scanner.java:1468)
      		at TryToReadFromClosedFile.main(TryToReadFromClosedFile.java:22)
       */		 
         System.out.println (" picked up *"  + temp + "*");
       
      }
   }	 
