0
我的應用程序每天都會創建一個新的CSV文件。 現在我想寫一些新的信息。當我按下按鈕時會發生這種情況。 我的問題是,我不知道如何打開現有文件,並繼續最後一次寫入信息的位置。我確實嘗試了很多,但是我沒有找到解決方案。將信息導入現有的csv文件android
創建文件
File myFile = new File("/sdcard/Protokolle" + date
+ "/Protokoll.csv");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append("Date");
myOutWriter.append(',');
myOutWriter.append(date);
myOutWriter.append('\n');
myOutWriter.append('\n');
myOutWriter.close();
fOut.close();
的onClick
FileWriter fWriter;
try {
File sdCardFile = new File("/sdcard/Protokolle" + date + "/Protokoll.csv");
Log.d("TAG", sdCardFile.getPath());
fWriter = new FileWriter(sdCardFile, true);
fWriter.write("\n");
fWriter.write("Test");
fWriter.write("Test");
fWriter.write("\n");
fWriter.write("test");
fWriter.flush();
fWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
一個簡單的,也許不專業的方法是讀取文件,遍歷所有行,並在此過程後追加一個新行。 – reporter 2014-10-20 08:56:56