import java.util.Scanner; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; /** * This program counts the number of words found in a dictionary. * * @author Dave Slemon * @version v101 */ public class ReadingFiles { //main public static void main(String[] args) throws FileNotFoundException { //main Scanner words; String item="", backwards=""; long count=0; //open dictionary try { words = new Scanner(new FileInputStream(new File ("small.txt"))); //read from dictionary while (words.hasNextLine()) { //w item = words.nextLine(); System.out.println(item); count++; } //w System.out.println(count + " words found"); words.close(); } catch (FileNotFoundException e) { System.out.println("Error: file not found"); } } //main } //main