java 파일 쓰기 질문
아래 소스에서
마지막에 결과를 파일로 스고 싶습니다.
파일스기 방법좀 알려 주세요
---------test_sum_process-------------------
package test_sum;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
public class test_sum_process {
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"); // Log Dir
String tmpFile = f+"/tmp"; // Temp File
String result = f+"/result.txt"+"_"+stat_date; // Result File
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)
{
String readFile = f+"/"+file.getName();
try {
BufferedReader in = new BufferedReader(new FileReader(readFile));
//System.out.println(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.-]", "");
BufferedWriter out = new BufferedWriter(new FileWriter(tmpFile,true));
StringBuffer str1 = new StringBuffer(codename);
StringBuffer str2 = new StringBuffer(codecnt);
out.write(str1 + " " + str2 + "\n");
out.flush();
}
in.close();
} catch (IOException e) {
System.out.println(e);
}
}
Scanner in2 = new Scanner(new File(tmpFile));
HashMap map = new HashMap();
HashMap map2 = new HashMap();
ArrayList order = new ArrayList();
ArrayList order2 = new ArrayList();
String cntname;
Double logcnt;
while (in2.hasNext()) {
cntname = in2.next();
logcnt = in2.nextDouble();
if (!cntname.equals("이거아님")) {
if (!map.containsKey(cntname)) {
LogList s = new LogList(cntname, logcnt);
order.add(s);
map.put(cntname, s); // 사용자를 기억해놓습니다
}
map.get(cntname).addScore(logcnt);
}
else if (cntname.equals("이거아님")) {
if (!map2.containsKey(cntname)) {
LogList2 s = new LogList2(cntname, logcnt);
order2.add(s);
map2.put(cntname, s); // 사용자를 기억해놓습니다
}
map2.get(cntname).addScore2(logcnt);
}
}
}
}
댓글 달기