importjava.util.*;importjava.io.*;publicclassRead2{publicstaticvoidmain(Stringargs[])throwsException{//对文档进行词频处理,以下是代码部分BufferedReaderbr=newBufferedReade...
import java.util.*;
import java.io.*;
public class Read2 {
public static void main(String args[])throws Exception {
//对文档进行词频处理,以下是代码部分
BufferedReader br = new BufferedReader(new FileReader("java.txt"));
StringBuffer sb = new StringBuffer();
Set singleSet = new HashSet();
String temp = br.readLine();
while (null != temp){//循环以行为单位不断读数据,存储在一个StringBuffer里
sb.append(temp + " ");
temp = br.readLine();
}
String[] Str = sb.toString().split("[^A-Za-z0-9]");
for(String string:Str){
singleSet.add(string);
}
for (String childString : singleSet){
int count =0;
for (String fatherString : Str){
if (fatherString.equals(childString)){
count++;
}
}
System.out.println(childString+count);
}
}
}
有谁回答了吗?为什么看不见
展开