私はmysqlから読み込み、結果をtxtファイルに書き込もうとしています。ご覧のとおり、私はApacheのCommons IOを使います。結果セットにはつぶやきが含まれており、以下のすべてのSQLクエリはほぼ725行を返してtxtファイルに記録されます。私の問題は書き込み速度です、非常に遅いです(毎秒2-3kb)。私はここに何かを逃していますかFileUtils.write writing 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でファイル操作を行って以来、長い時間がかかりました。今はnoobの間違いを見ています。しかし、当時はコモンズを使用するのが妥当と思われました。あなたの提案をどのように実装できますか?コモンズでそれを行う方法はありますか?別の方法を使用すべきですか? –
@Aaron Clifton 'File'ではなく' FileOutputStream'を使用し、 'IOUtils.write(fos、content、" UTF8 ");を使用します。 – davidxxx