查找文件中的字母个数

package com.search.test;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class LanDiao {
	private static final String FILE_PATH="c:/chars.txt";
	public static void main(String[] args) {
		File f = null;
		FileInputStream fs = null;
		BufferedInputStream bis = null;
		byte[] b = new byte[10000];
		String str = null;
		String[] strArr = null;
		String charStr = "abcdefghijklmnopqrstuvwxyz";
		String[] charArr = charStr.split("");
		Map map = new HashMap();
		try {
			f = new File(FILE_PATH);
			fs = new FileInputStream(f);
			bis = new BufferedInputStream(fs);
			bis.read(b);
			str = new String(b);
			str = str.trim();
			strArr = str.split("");
			for (int i=1; i<charArr.length; i++) {
				int num = 0;
				for (int j=0; j<strArr.length; j++) {
					if(charArr[i].equalsIgnoreCase(strArr[j])) {
						num++;
					}
					map.put(charArr[i], String.valueOf(num));
				}
			}
			for (int i=1; i<charArr.length; i++) {
				System.out.println(charArr[i]+"有:"+map.get(charArr[i])+"个");
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				bis.close();
				fs.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			
		}
	}

}

你可能感兴趣的:(java,C++,c,F#,J#)