看看行不
package test;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
public class test6 {
public static void main(String[] args) throws IOException{
Scanner scan = new Scanner(System.in);
String str = null;
while((str = scan.nextLine()) != null){
if("heima".equals(str)){
readFile();
break;
}else{
System.out.println("请重新输入密码");
}
}
}
public static void readFile() throws IOException{
TreeMap<Character,Integer> m = new TreeMap<Character,Integer>();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("d:\\a.txt"));
int by = 0;
while((by=bis.read()) != -1){
if(by < '0' || by > '9'){
System.out.print((char)by);
if(!m.containsKey((char)by)){
m.put((char)by, 1);
}else{
m.put((char)by, m.get((char)by) + 1);
}
}
}
Set<Entry<Character, Integer>> set = m.entrySet();
Iterator<Entry<Character, Integer>> it = set.iterator();
while(it.hasNext()){
Entry<Character,Integer> e = it.next();
System.out.print(e.getKey() + ":" + e.getValue() + "\t");
}
}
}
|