package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class test1 {
public static void main(String[] args) throws IOException {
Map<Character,Integer> map=new HashMap<>();
BufferedReader buff=new BufferedReader(new FileReader("d:"+File.separator+"22.txt"));
PrintWriter prin=new PrintWriter(new FileOutputStream("d:"+File.separator+"222.txt"),true);
String str=null;
char[] ch=null;
while((str=buff.readLine())!=null)
{
ch=str.toCharArray();
for(int i=0;i<ch.length;i++)
{
if(map.get(ch[i])==null)
{
map.put(ch[i],1);
}
else
{
int k=map.get(ch[i]);
k++;
map.put(ch[i],k);
}
}
}
Set<Map.Entry<Character,Integer>> set=map.entrySet();
for(Iterator<Map.Entry<Character,Integer>> i=set.iterator();i.hasNext();)
{
Map.Entry<Character,Integer> k=i.next();
System.out.println(k.getKey()+"("+k.getValue()+")");
prin.println(k.getKey()+"("+k.getValue()+")");
}
}
}
|
|