I'm printing the data to a file but this data is overwritten. How can I collect all data in one file
Future<String?> get _localPathBLE async {
final directory = await getExternalStorageDirectory();
return directory?.path;
}
Future<File> get _localFile async {
final path = await _localPathBLE;
var date =
DateUtil.instance.dateParseToString(DateEnum.FULL, DateTime.now());
return File('$path/DATA.csv');
}
Future<void> writeBLE(List<List<double>> acc3d) async {
final file = await _localFile;
String csv = const ListToCsvConverter().convert(acc3d);
// Write the file
return file.writeAsStringSync(csv);
}
CodePudding user response:
In order to append the bytes to an existing file, pass FileMode.append as the optional mode parameter.
See writeAsStringSync for details.
CodePudding user response:
Future<void> writeBLE(List<List<double>> acc3d) async {
final file = await _localFile;
String csv = const ListToCsvConverter().convert(acc3d);
// Write the file
return file.writeAsStringSync(csv '\n',
mode: FileMode.append, flush: true);
}