代碼:
package com.test.wordcount;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class WordCount {
private static String path_src = "/home/CORPUSERS/xp009835/shenma.txt";
private static String path_result = "/home/CORPUSERS/xp009835/shenma_result.txt";
private static BufferedReader br = null;
private static BufferedWriter bw = null;
private static String line_current = null;
private static String[] words = null;
private static List<String> word_list = new ArrayList<String>();
public static void main(String[] args) {
File file = new File(path_src);
if (!file.exists()) {
System.out.println("file " + file + " is not existed, exit");
return;
}
try {
br = new BufferedReader(new FileReader(file.getPath()));
line_current = br.readLine();
while (line_current != null) {
words = line_current.split(" |,|\\.");
for (String s : words) {
if (!s.equals(""))
word_list.add(s);
}
line_current = br.readLine();
}
for (String temp : word_list) {
System.out.println(temp);