//Try with java SortWords tomorrow.txt import java.util.*; import java.io.*; public class CountWords { private static final Integer ONE = new Integer(1); public static void main(String args[]) { FileInputStream fis; InputStreamReader isr; BufferedReader br; StreamTokenizer strt; Map mapOfWords = new TreeMap(); List listOfWords = new ArrayList(); String fn = args[0]; try { fis = new FileInputStream(args[0]); isr = new InputStreamReader(fis); br = new BufferedReader(isr); strt = new StreamTokenizer(br); strt.lowerCaseMode(true); strt.whitespaceChars('?','?'); strt.whitespaceChars('.','.'); strt.whitespaceChars(',',','); strt.whitespaceChars(';',';'); strt.whitespaceChars(':',':'); while (strt.nextToken() != StreamTokenizer.TT_EOF) { if (strt.ttype == StreamTokenizer.TT_WORD) { listOfWords.add(strt.sval); Integer freq = (Integer) mapOfWords.get(strt.sval); if (freq==null) { mapOfWords.put(strt.sval,ONE); } else { mapOfWords.put(strt.sval,new Integer(freq.intValue()+1)); } } } } catch (FileNotFoundException e){ System.out.println("Fichier " + fn + " pas trouve"); System.exit(0); } catch (IOException e) { System.out.println("IO Exception"); } System.out.println(mapOfWords.size() + " distinct words detected:"); System.out.println(mapOfWords); System.out.println(listOfWords.size() + " words detected:"); System.out.println(listOfWords); } }