日期:2014-05-20 浏览次数:20734 次
package test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.*;
public class FileCount {
public static void main(String[] args) throws Exception {
//先读取A.txt,将编码和账号存储到map中
FileReader afr = new FileReader("C:/java_test/A.txt");
BufferedReader ar = new BufferedReader(afr);
String aline = null;
Map<String, String> codeMap = new HashMap<String, String>();
while ((aline = ar.readLine()) != null) {
String[] array = aline.split("\\
------解决方案--------------------
");
codeMap.put(array[4], array[2]);
}
ar.close();
//再读取B.txt,将交易信息存储到map中
FileReader fr = new FileReader("C:/java_test/B.txt");
BufferedReader br = new BufferedReader(fr);
String line = null;
Map<String, int[]> map = new HashMap<String, int[]>();
while ((line = br.readLine()) != null) {
String[] array = line.split("\\
------解决方案--------------------
");
String acct = array[1];
int[] count = map.get(acct);
if (count == null) {
count = new int[] { 0, 0, 0 };
map.put(acct, count);
}
int amt = Integer.parseInt(array[2]);
if (amt >= 0) {
count[0] += 1;
} else {
count[1] += 1;
}
if ("1".equals(array[3])) {
count[2] += 1;
}
}
br.close();
FileWriter fw = new FileWriter("c:/java_test/C.txt");
BufferedWriter bw = new BufferedWriter(fw);
int j = 0;