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