统计文本文件中单词出现频率(用java集合框架编写)求高手指教?? 从文本文件中读取文本,文本文件名被作为命令行参数传递,统计单词不区分大小写。如果第一个字符不是字母,就不统计这个单词,以字典序显示输出,每个单词后面紧跟它的出现次数。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.*;import java.util.*;public class Test{ public static void main(String args[])throws Exception{ File file = new File("d:\\src\\Test.java"); display(file); } public static void display(File file)throws Exception{ BufferedReader br = new BufferedReader(new FileReader(file)); String line = null; TreeMap<String,Integer> tm = new TreeMap<String,Integer>(); while((line=br.readLine())!=null){ line.toLowerCase(); String reg1 = "\\s+"; String reg2 ="\\w+"; String str[] = line.split(reg1); for(String s: str){ if(s.matches(reg2)){ if(!tm.containsKey(s)){ tm.put(s,1); } else{ tm.put(s,tm.get(s)+1); } } } } System.out.println(tm); }} String reg2 ="^[a-zA-Z]\\w*"; String reg1 = "\\s+";String reg2 ="\\w+";这两行是什么意思啊? 分享 趋势科技的一道程序题(武汉地区考题) 紧急的线程问题 关于强制转换对象有个几个好奇的问题想问下,请高手解答~~~ 在线等,请各位大虾帮帮忙,谢谢 大家项目中使用ANT了吗? 哪位有得到手机号段所属区域的代码?谢谢 菜鸟问题:请问关于KeyTyped和KeyPressed事件的疑问。 求将"d:\file.txt"转成"d:/file.txt"最好的方法! 为什么我在JBuilder5中无法在调试中进入方法内部? java的引用是不是c语言的指针? 如何得到java工程下文件路径 java se 不知道错哪里?
import java.io.*;
import java.util.*;public class Test{
public static void main(String args[])throws Exception{
File file = new File("d:\\src\\Test.java");
display(file);
}
public static void display(File file)throws Exception{
BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;
TreeMap<String,Integer> tm = new TreeMap<String,Integer>();
while((line=br.readLine())!=null){
line.toLowerCase();
String reg1 = "\\s+";
String reg2 ="\\w+";
String str[] = line.split(reg1);
for(String s: str){
if(s.matches(reg2)){
if(!tm.containsKey(s)){
tm.put(s,1);
}
else{
tm.put(s,tm.get(s)+1);
}
}
}
}
System.out.println(tm);
}
}
String reg2 ="\\w+";
这两行是什么意思啊?