import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; /** * Write a description of class text here. * * @author (your name) * @version (a version number or a date) */ public class text { /** * * Java program to read file using Scanner class in Java. * java.util.Scanner is added on Java 5 and offer convenient method to read data * * @author */ public static void main() throws FileNotFoundException { long lineNumber = 0; String line; //creating File instance to reference text file in Java File text = new File("words.txt"); //Creating Scanner instnace to read File in Java Scanner keybd = new Scanner(text); //Reading each line of file using Scanner class lineNumber = 1; while(keybd.hasNextLine()){ line = keybd.nextLine(); System.out.println("line " + lineNumber + " :" + line); lineNumber++; } System.out.println(lineNumber + " words were successfully read."); } }