1
我想從mysql讀取並將結果寫入一個txt文件。正如你所看到的,我使用Apache的Commons IO。結果集包含推文,並且下面的每個SQL查詢幾乎返回725行,以便寫入txt文件。我的問題是寫入速度很慢(每秒2-3kb)。我在這裏錯過了什麼嗎?FileUtils.write寫入速度
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上進行文件操作以來,已經很長時間了,所以現在我看到了noob錯誤。但那個時候使用普通人似乎是合理的。我怎樣才能實施你的建議?有沒有辦法與commons做它,或者我應該使用另一種方法? –
@Aaron Clifton只需使用'FileOutputStream'而不是'File'並使用'IOUtils.write(fos,content,「UTF8」);' – davidxxx