0
try {
while ((inputLine = bufferedReader.readLine()) != null) {
String[] words = inputLine.split("[ \n\t\r.,;:!?(){}]");
for (int wordCounter = 0; wordCounter < words.length; wordCounter++) {
String key = words[wordCounter].toLowerCase();
if (key.length() > 0) {
if (map.get(key) == null) {
map.put(key, 1);
}
else {
int value = map.get(key).intValue();
value++;
map.put(key, value);
}
}
Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
for (Map.Entry<String, Integer> entry : entrySet) {
System.out.println(entry.getValue() + "\t" + entry.getKey());
}
}
} catch (IOException error) {
System.out.println("Invalid File");
}
你不改變'input'。 – 4castle
如果您使用的是Java 7+,則可能需要使用[用於在同一catch子句中捕獲多個異常類型的語法](http://stackoverflow.com/q/3495926/5743988)。 – 4castle