/* * Intro to Programming CSE 1310 * University of Texas at Arlington */ package code18sepf18; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; /** * * @author jcmtiernan */ public class Code18SepF18 { /** * @param args the command line arguments */ public static void main(String[] args) { File inputFile = new File ("bookYearSciFi.txt"); // where is the file created and where can NetBeans see it? Scanner inFile; Scanner input = new Scanner(System.in); // attaching input file to scanner in a try-catch try { inFile = new Scanner(inputFile); } catch (FileNotFoundException fnfe) { inFile = new Scanner(System.in); System.out.println("Input file was not found"); } int year; // read data until file is empty //for (int j = 0; j < 40; j++) while (inFile.hasNextInt()) { year = inFile.nextInt(); System.out.println("Program read in year "+year); } System.out.println("All data has been read"); File inputFile2 = new File ("bookYearTitleSciFi.txt"); // where is the file created and where can NetBeans see it? Scanner inFile2; // attaching input file to scanner in a try-catch try { inFile2 = new Scanner(inputFile2); } catch (FileNotFoundException fnfe) { inFile2 = new Scanner(System.in); System.out.println("Input file was not found"); } int year2 = 0; String title2 = ""; // read data until file is empty //for (int j = 0; j < 40; j++) while (inFile2.hasNextInt()) { year2 = inFile2.nextInt(); title2 = inFile2.nextLine(); System.out.println("Program read in year2 "+year2+" and title "+title2); } System.out.println("All data has been read from bookYearTitleSciFi"); File inputFile3 = new File ("bookYearTitleSeriesSciFi.txt"); // where is the file created and where can NetBeans see it? Scanner inFile3; // attaching input file to scanner in a try-catch try { inFile3 = new Scanner(inputFile3); } catch (FileNotFoundException fnfe) { inFile3 = new Scanner(System.in); System.out.println("Input file was not found"); } int year3; String title3; // read data until file is empty //for (int j = 0; j < 40; j++) while (inFile3.hasNextInt()) { year3 = inFile3.nextInt(); title3 = inFile3.nextLine(); System.out.println("Program read in year3 "+ year3+" and title "+title3); } System.out.println("All data has been read"); } }