import java.util.*; import java.io.*; public class WordMap { public static void main (String [] args) { TreeMap unique = new TreeMap(); FileReader infile=null; try { infile = new FileReader("output.txt"); Scanner sc = new Scanner(infile); String newword=null; int wordvalue=0; while (sc.hasNext()) { newword=sc.next(); System.out.println("the word is: " + newword); if (unique.containsKey(newword)) { wordvalue = unique.get(newword); wordvalue++; unique.put(newword,wordvalue); } else unique.put(newword,1); } System.out.println("unique words: " + unique); } catch (FileNotFoundException ffe) { System.out.println("the file does not exist"); }//end catch finally { try { infile.close();}//end try catch (IOException ioe) {System.out.println("Problem closing the file");} }//end finally } }