只要isSaveCSV()为true,我会尝试将GPS数据从我的Android 7智能手机导出到.csv文件一段时间。
public void saveCSVfile() {
if (isSaveCSV()) {
Long time = System.currentTimeMillis()/1000;
String entry =time.toString()+","+lat+","+lon+"\n";
if (csv_created==false) {
csv_created=true;
FILECOUNT++;
NEWFILENAME = FILENAME+FILECOUNT+".csv";
File myDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "tensorflow");
csvfile = new File(myDir, NEWFILENAME);
try {
FileOutputStream out = new FileOutputStream(csvfile);
out.write( entry.getBytes() );
out.close();
} catch (final Exception e) {
LOGGER.e(e, "Exception!");
}
}else {
try {
entry="TESTFORFOOSAKE";
FileOutputStream out = openFileOutput(csvfile.getName(), Context.MODE_APPEND);
out.write(entry.getBytes());
out.close();
} catch (final Exception e) {
LOGGER.e(e, "Exception!");
}
}
}else {
csv_created=false;
}
}
文件始终是一行。.我从未见过双行文件。.
答案 0 :(得分:-1)
如果要追加到现有文件,则应使用带有布尔参数的重载构造函数:
FileOutputStream out = new FileOutputStream(csvfile, true);
// Here ---------------------------------------------^