以下是JAVA中三种方式实现文件字符统计
package com.lyc.gui;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
- 统计一个文件countCharNum2.txt中各个字母出现次数,
- 显示格式:A(8),B(16),C(10)…,a(12),b(10),c(3)…中(5),国(6),
- 括号内代表字符出现次数countCharNum2.txt:AAaaaBBBBbbbCccDDDddddEefFF中国中国中国中中中国
- @author JLB
*/
public class Demo03
{
public static void main(String[] args) throws IOException
{
FileReader fr = new FileReader("F:\\培训\\课程\\2018-12-14\\作业\\ss.txt");
HashMap<Object,Integer> map = new HashMap<Object,Integer>();
//Set<Integer> set = new HashSet<Integer>();
int i;
int a=1;
while( (i = fr.read()) !=-1 )
{
char ss = (char)i;