java 같은 항목의 합계 질문

h2ogid의 이미지

java 에서

합계를 구하려는데

파일이 여러개고 구하려는 값도 여러개 입니다.

1.txt 에 내용이

aaa : 1a

bbb : 2.0

ccc : 4

2.txt 에 내용이

aaa : 4

bbb : 0.1s

ddd : 4

3.txt 에 내용이

aaa : 4

bbb : 6.3d

ccc : 2

eee : 4

......

어렇게 되어있을 때

result.txt 가 숫자 뒤의 문자를 제거하고,

aaa : aaa의 합

bbb : bbb의 합

ccc : ccc의 합

ddd : ddd의 합

eee : eee의 합

이렇게 되게 하고 싶습니다.

구분자를 : 로 구분 하여서

아래와 같이 해봤는데

이후에 합계를 구하려고 하는데 도움좀 주시면 감사하겠습니다.

-------------------------

package test_stat_sum;

import java.util.*;
import java.io.*;

public class test_stat_sum {

public void statsum(String codename, String codecnt) {

String str1 = new String(codename);
String str2 = new String(codecnt);
Double cnt = Double.parseDouble(str2);

Map map = new HashMap();

map.put(str1, cnt);

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

while (iterator.hasNext()) {
String key = (String) iterator.next();
if(key.equals("LogCount(crystaldebugging)")){
Double totcnt = 0.0;
totcnt += map.get(key) ;
System.out.print(totcnt); //--> 여기서 합이 String 연결로 나옴
}

}

}

public static void main(String[] args) throws IOException,FileNotFoundException{
Scanner dateinput = new Scanner(System.in); // script parameter -- date values
String stat_date = dateinput.next();

ArrayList txtFiles= new ArrayList();
File f= new File("D:/AADEV_LGE/workspace/test_stat_sum/rsc");

if(!f.exists())
{
System.out.println("not found dir");
return;
}

File[] allFiles= f.listFiles();
for(File file : allFiles)
{
if(file.getName().startsWith(stat_date))
{
txtFiles.add(file);

}
}

for(File file : txtFiles)
{
//System.out.println(file.getName());
String readFile = f+"\\"+file.getName();
//System.out.println(readFile);

try {
BufferedReader in = new BufferedReader(new FileReader(readFile));

String line = "";
while ((line = in.readLine()) != null) {

if (line.indexOf(":") < 0)
continue;
// System.out.println(line);
String[] arr = line.split(":");

String codetmp = arr[0] ;

String cnttmp = arr[1] ;

String codename = codetmp.replaceAll("[- ]", "");
String codecnt = cnttmp.replaceAll("[^0-9.-]", "");

test_stat_sum test_stat_sum = new test_stat_sum();
try {
test_stat_sum.statsum(codename,codecnt);

} catch (Exception e) {
e.printStackTrace();
}



}
in.close();


} catch (IOException e) {
System.out.println(e);
}



}

}
}