package chapter22;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
public class practice9 {
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage: java practice9 fullfilename");
System.exit(0);
}
String filename = args[0];
Map map = new HashMap();
try {
Scanner in = new Scanner(new File(filename));
String line;
while ((line = in.nextLine()) != null) {
String[] words = line.split("[\t\r\n,.;:!?(){]");
for (int i = 0; i < words.length; i++)
if (!map.containsKey(words[i]))
map.put(words[i], 1);
else
map.put(words[i], map.get(words[i]).intValue() + 1);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Set<Entry<String, Integer>> entrySet = map.entrySet();
for(Map.Entry<String, Integer> entry:entrySet){
System.out.println(entry.getKey()+entry.getValue());
}
}