/**
* Example to illustrate reading numbers from a file where the user chooses the
* filename - added a boolean variable to avoid reading from a file that wasn't
* found but am still getting error message that fileScan night not have been initilized
*
* @author Elizabeth Adams
* @version 1
*/
import java.util.Scanner;
import java.io.*;

public class ReadFromFile_1c
{
   public static void main (String[] args)  throws FileNotFoundException
   {
      Scanner fileScan, scan;
      String  filename;
		int number;
		int count;
		boolean fileFound;
		
		// initialize count and fileFound
		count = 0;
		fileFound = false;
		
		// set Scanner to read from keyboard
		scan = new Scanner (System.in);
		
		// prompt to get filename from user
		System.out.println 
		     (" Please enter the name of the file you want to read from");
		System.out.print (" with complete path ");
		
		// get filename
		 		filename = scan.nextLine();
     
      // set Scanner to read from desired file 		
		try
		{
				fileScan = new Scanner (new File (filename));
				fileFound = true;
      }
 	   catch (FileNotFoundException fnfe)
		{
		   System.out.println (" The file you named was not found ");
		}

		
      // Read and process each line of the file
      while ( (fileFound) && (fileScan.hasNext()))
      {
         number = fileScan.nextInt();
         System.out.println (" got number " + number);
			count++;
      }
		
		// when out of data print ending message
      System.out.println (" read " + count + " numbers from file - am now done ");
	}	
}
