import java.util.Scanner; //for scanner class import java.io.*; //File and IOException //read data from a file public class Ex17FileRead { public static void main(String[] args) throws IOException { Scanner keyboard = new Scanner(System.in); //Get the filename System.out.print("Enter the filename: "); String filename = keyboard.nextLine(); //open the file File myFile = new File(filename); Scanner inputFile = new Scanner(myFile); while (inputFile.hasNext()) { String myLine = inputFile.nextLine(); System.out.println(myLine); } //close the file inputFile.close(); } }