首先,你结果里面的那个编码是什么意思?
我感觉要输出你的结果,只要b文件就可以了
给你个思路,扫描b文件,
然后建一个hashmap(K,V) key=帐号 value=new Integer[3]{入金次数,出金次数,成功次数}
然后扫描每一行做一个
while(hashmap.contains(K))
{
if(金额>0)入金次数+1
if(金额<0)出金次数+1
if(结果=1)成功次数+1
}
我感觉要输出你的结果,只要b文件就可以了
给你个思路,扫描b文件,
然后建一个hashmap(K,V) key=帐号 value=new Integer[3]{入金次数,出金次数,成功次数}
然后扫描每一行做一个
while(hashmap.contains(K))
{
if(金额>0)入金次数+1
if(金额<0)出金次数+1
if(结果=1)成功次数+1
}
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;
for (Map.Entry<String, int[]> entry : map.entrySet()) {
int[] count = entry.getValue();
StringBuffer sb = new StringBuffer();
sb.append(codeMap.get(entry.getKey())).append("|");
sb.append(entry.getKey()).append("|").append(count[0]).append("|").append(count[1])
.append("|").append(count[2]).append("\r\n");
bw.write(sb.toString());
j++;
if (j % 100 == 0) {
bw.flush();
}
}
bw.close();
}
}