what's the equivalent fileoutputstream of java in dart? Java code
file = new FileOutputStream(logFile, true);
file.write("String");
java file output
String
Ive tried this in dart Dart code
var file = File(logFile!.path).openWrite();
file.write("String");
[String]
and every time I open the file again to append "String2" and "String3" to it, the output will be
[String][String2][String3]
as oppose to java's output
StringString3String3
to sum it up, is there a way to fix/workaround this? why each array bytes written in dart will be a new array instead of append into an existing one?
CodePudding user response:
You can achieve that by using File.writeAsString()
and using FileMode.append.
Picking up your example, this would be:
var file = File(logFile!.path);
file.writeAsString("String", mode: FileMode.append);
CodePudding user response:
did you try writeAsString() ?
import 'dart:io';
void main() async {
final filename = 'file.txt';
var file = await File(filename).writeAsString('some content');
// Do something with the file.
}