package Timu;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class Test6 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
FileReader fr=new FileReader(new File("aaa.txt"));
FileWriter fw=new FileWriter("ccc.txt");
HashMap<Character,Integer> hm=new HashMap<Character,Integer>();
String s=null;
int count;
char c;
while ((count=fr.read())!=-1){
c=(char)count;
if (!hm.containsKey(c)) {
hm.put(c, 1);
}else{
hm.put(c, hm.get(c)+1);
}
}
fr.close();
for (Entry<Character,Integer> entry :hm.entrySet()) {
fw.write(entry.getKey()+":"+entry.getValue()+"\n");
fw.flush();
}
fw.close();
}
}
昨天我自己做了一个 你可以参考下!! |