import java.io.*; import java.util.Scanner; public class SalesOfCoffee{ // the next three variables are related to the scanner. private static final String FILE_NAME = "coffee.csv"; private static Scanner myScanner; // indicate if the scanner is valid or not. private static boolean validScanner = false; public static void main(String[] args){ String line; int totalLines = 0; MakeScanner(); if (!validScanner) { System.out.printf("Scanner not constructed\n"); return; } myScanner.nextLine(); while(myScanner.hasNextLine()) { line = myScanner.nextLine(); totalLines++; System.out.printf("Got '%s'\n", line); } System.out.printf("The file contains %d lines.\n",totalLines); myScanner.close(); } private static void MakeScanner() { try { myScanner = new Scanner(new File(FILE_NAME)); validScanner = true; } catch (FileNotFoundException e) { System.out.printf("Cound not open %s", FILE_NAME); } } }