最近公司的产品建议和反馈中经常出现@@::@@,然后写个小工具去分析一下2.5G的访问日志,看看什么情况
public static void main(String[] args){
String regEx="((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)";
Pattern p = Pattern.compile(regEx);
Map<String,Integer> mapIp=new HashMap<>();
ArrayList<String> arrayList = new ArrayList<>();
String path="C:\\Users\\xiongyi\\Desktop\\服务器日志\\access.log";
try {
FileReader fr = new FileReader(path);
BufferedReader bf = new BufferedReader(fr);
String str="";
// 按行读取字符串
while ((str = bf.readLine()) != null) {
if(str.contains("/opinion/pourForth")){
arrayList.add(str);
}
}
bf.close();
fr.close();
} catch (IOException e) {
e.printStackTrace();
}finally {
arrayList.forEach(a->{
System.out.println(a);
Matcher m = p.matcher(a);
if(m.find()){
String group = m.group();
if (mapIp.get(group) == null) {
mapIp.put(group, 1);
} else {
mapIp.put(group, mapIp.get(group) + 1);
}
}
});
System.out.println("==========================entrySet========================");
mapIp.entrySet().stream().forEach(System.out::println);
System.out.println("=======================keySet===========================");
mapIp.keySet().stream().forEach(System.out::println);
}
}