mysql에서 읽고 txt 파일에 결과를 쓰려고합니다. 보시다시피 저는 Apache의 Commons IO를 사용합니다. 결과 집합에는 트윗이 포함되어 있으며 아래의 모든 SQL 쿼리는 txt 파일에 기록 될 725 개의 행을 거의 반환합니다. 제 문제는 쓰기 속도입니다. 매우 느립니다 (초당 2-3kb). 내가 여기서 뭔가를 놓치고 있니?FileUtils.write write speed
Statement stmt2 = connection.createStatement();
for (int week = 0 ; week<hashTag.length/15 ; week++){
File container = new File("C:\\Users\\COMP\\Desktop\\threeMonthsSplitTxt\\weeklyBinsTwitter\\week"+week+"-"+hashTag[week]+".txt");
for(int hash = 0 ; hash<15 ; hash++){
ResultSet results = stmt2.executeQuery("select tweetContent
from threemonthswithhashtag
where hashTag = '"+hashTag[hashCount]+"'
and tweetCreatedTime between '"+firstDate[hashCount]+"'
and '"+ lastDate[hashCount]+"';");
while(results.next()){
tweetContent = results.getString("tweetContent");
try{
FileUtils.write(container,newLine,"UTF8",true);
FileUtils.write(container,tweetContent,"UTF8",true);
}catch(IOException e){e.getMessage();}
}
hashCount++;
}
}
_ 이것이 당신에게 최적의 성능을주지 못한다는 사실에 놀랐습니까? _ _ -이 의견은 귀하의 답변에 전혀 기여하지 않습니다. – OldCurmudgeon
Java에서 파일 조작을한지 꽤 오래되었으므로 이제 멍청한 실수를 봅니다. 그러나 그 당시 공용어를 사용하는 것이 합리적으로 보였습니다. 제안을 어떻게 구현할 수 있습니까? 공유지로 할 수있는 방법이 있습니까? 아니면 다른 방법을 사용해야합니까? –
@Aaron Clifton'File'보다는'FileOutputStream'을 사용하고'IOUtils.write (fos, content, "UTF8");을 사용합니다. – davidxxx