1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class AnalyticsCounterV2 {
private static final String FILENAME = "C:\\\xxx.txt";
public static void main(String[] args) throws FileNotFoundException, IOException {
Map list = new HashMap();
try (BufferedReader br = new BufferedReader(new FileReader(FILENAME))) {
StringBuffer sb = new StringBuffer();
String line = br.readLine();
while (line != null) {
String[] words = line.split(" ");
for (int i = 0; i < words.length; i++) {
if (list.get(words[i]) == null) {
list.put(words[i], 1);
} else {
int newValue = Integer.valueOf(String.valueOf(list.get(words[i])));
newValue++;
symptomslist.put(words[i], newValue);
}
}
sb.append(System.lineSeparator());
line = br.readLine();
}
}
HashMap<String, String> sorted = new HashMap<String, String>(list);
for (Object key : sorted.keySet()) {
System.out.println(key + " : " + list.get(key));
}
}
} |
Partager