import java.io.*; public class BuildDict { private static BufferedReader console = new BufferedReader( new InputStreamReader( System.in ) ); //private static Dictionary d = new Dictionary(10501); private static Dictionary d = new Dictionary(5003); public static void processLine(String line) { String word = ""; char ch; for(int i = 0; i < line.length(); i++) { // ch is the current character ch = line.charAt(i); // if ch is a letter, append it to the word // being constructed if(Character.isLetter(ch)) word = word + ch; // otherwise, if ch is not a letter // and there is a word to insert into dictionary else if(word.length() > 1) { word = word.toLowerCase(); if(d.search(word) == null) { Record temp = new Record(word); d.insert(temp); } word = ""; } else if(word.length() == 1) word = ""; } if(word.length() > 1) { word = word.toLowerCase(); if(d.search(word) == null) { Record temp = new Record(word); d.insert(temp); } } } public static void main(String [] args) { try { System.out.println("Please type the name of the files you want processed."); String filenames = console.readLine(); String[] fileNameArray = filenames.split("[ \t]+"); FileOutputStream outFile; outFile = new FileOutputStream("words.dat"); PrintStream p = new PrintStream(outFile); String line = ""; for(int i = 0; i < fileNameArray.length; i++) { FileReader fr = new FileReader(fileNameArray[i]); BufferedReader stdin = new BufferedReader(fr); line = stdin.readLine(); while(line != null) { processLine(line); line = stdin.readLine(); } } d.print(p); d.printStatistics(); p.close(); } catch(java.io.IOException e) { System.out.println(e); } } }