处理方法及思路参考：

1、首先建立一个字典（数组或字符串）；

2、把文件中的单词装入这个字典；

3、对字典进行检索，对每个单词进行计数；

import java.io.*;

import java.util.*;

public class WordCount {

final static Integer ONE = new Integer(1);

final static String DELIMITERS = " \t\n\r\f.,<>\"\'=/;()-@|`$";

static Map map = new HashMap();

// Return the map

public static Map getMap() {

return map;

}

// Clear the map

public void clear() {

map.clear();

}

private static void addWords(String line) {

// Get map

Map map = getMap();

// Split words

StringTokenizer tokenizer = new StringTokenizer(line, DELIMITERS);

// For each word

while (tokenizer.hasMoreTokens()) {

// Get word

String key = tokenizer.nextToken();

// Get frequency

// If not fount, add word to map with count one

// Otherwise, add to map with old count + 1

Integer frequency = (Integer)map.get(key);

if (frequency == null) {

frequency = ONE;

} else {

int value = frequency.intValue();

frequency = new Integer(value + 1);

}

map.put(key, frequency);

}

}

private static void treatFile(String inFile) throws IOException {

BufferedReader in = null;

try {

in = new BufferedReader(new FileReader(inFile));

String line = null;

while ((line = in.readLine()) != null) {

addWords(line);

}

}finally{

if(in != null){

in.close();

}

}

}

private static void outputResult(String outFile) throws IOException{

BufferedWriter out = null;

Map map = getMap();

Iterator iterator = map.entrySet().iterator();

try{

out = new BufferedWriter(new FileWriter(outFile));

out.write("-------------------");

out.newLine();

out.write("µ¥´Ê\t\t\t\t³öÏÖÆµÂÊ\n");

out.newLine();

out.write("-------------------");

out.newLine();

int i = 1;

while (iterator.hasNext()) {

Map.Entry entry = (Map.Entry)(iterator.next());

//System.out.println(entry.getKey() + "=" + entry.getValue());

System.out.print("µÚ "+i+"\r");

i++;

out.write(entry.getKey()+"\t\t\t\t"+entry.getValue());

out.newLine();

}

out.flush();

out.close();

System.out.println("\n´¦ÀíÍê±Ï!\nÎÄ¼þ£º"+outFile);

}finally{

if( out !=null ){

out.close();

}

}

}

public static void main(String[] args) throws IOException {

if (args.length != 2) {

System.out.println("Ê¹ÓÃ·½Ê½£º\njava WordCount ÔÎÄ¼þ.txt Êä³öÎÄ¼þ.txt\n");

System.exit(0);

} else {

treatFile(args[0]);

outputResult(args[1]);

}

}

}