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);
}



}

}
}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.