import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.ArrayList;
import java.util.HashMap;
public class work {
public static void main(String[] arges) throws Exception
{
BufferedReader fr=new BufferedReader(new FileReader("D://java//src.txt"));
StringBuffer sbf=new StringBuffer();
String str=fr.readLine();
Map map=new HashMap();
while(str!=null)
{
sbf.append(str);
str=fr.readLine();
}
String sa=sbf.toString();
String[] a=sa.split(",|\\.|\\s");
for(int i=0;i<a.length;i++)
{
int k=0;
for(int j=0;j<a.length;j++)
{
if(a[i].equalsIgnoreCase(a[j]))
{
k++;
}
}
map.put(a[i], k);
}
BufferedWriter cf=new BufferedWriter(new FileWriter("D://java//resultRcorder.txt"));
cf.write("重复的元素为:"+map.keySet());
cf.write("分别重复的个数为"+map.values());
cf.flush();
}
}
老师这个