Java编写一个程序,统计一个文本文件所包含的不同单词的个数,并将结果保存在另一个文件中。输出文件的格式为:每个单词占用-行,其内容包括单词本身及其出现的次数:各单词之间要按照从小到大的顺序排列。
package Unit4;
import java.io.*;
import java.util.*;
public class DCpaixu {
static ArrayList<String> wordList = new ArrayList<String>();
public static void main(String[] args)throws FileNotFoundException{
// 使用ArrayList来存储每行读取到的字符串
ArrayList<String> arrayList = new ArrayList<String>();
try {
FileReader fr = new FileReader("E:/桌面—s/1桌面s/1资源pa/word.txt");
BufferedReader bf = new BufferedReader(fr);
String str;
// 按行读取字符串
while ((str = bf.readLine()) != null) {
arrayList.add(str);
}
bf.close();
fr.