package test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Scanner;
public class FindName {
public static void main(String[] args) throws FileNotFoundException {
ArrayList list = new ArrayList();
System.out.println("开始查看");
Scanner sc = new Scanner(new File("C://Path/To/File"));
while (sc.hasNextLine()) {
String str = sc.nextLine();
Pattern pattern = Pattern.compile("(?<=can[1-9] ).*?(?=#)");
Matcher matcher = pattern.matcher(str);
if (matcher.find())
;
String s = matcher.group();
list.add(s);
}
Map map = count(list);
System.out.println(map);
sc.close();
}
public static Map count(ArrayList list) {
Map map = new HashMap();
for (String s : list) {
if (map.containsKey(s)) {
Integer old = map.get(s);
map.put(s, old + 1);
} else {
map.put(s, 1);
}
}
return map;
}
}