import java.util.Scanner; import java.io.FileInputStream; import java.io.FileNotFoundException; /** FileInput2.java - Ask the user for a file name, and then open that file. */ public class FileInput2 { public static void main(String [] args) throws FileNotFoundException { Scanner kbd = new Scanner(System.in); System.out.print("What is the file name? "); String fileName = kbd.nextLine(); Scanner in = new Scanner(new FileInputStream(fileName)); int lineNumber = 0; while(in.hasNextLine()) { String line = in.nextLine(); ++lineNumber; } System.out.println("I found " + lineNumber + " lines."); } }