How do I concatenate string to an existing file?

append, dart, file

Solution

The FileMode is an optional, named parameter, so you have to specify its name ('mode') when you call it. To solve your problem, change this:

outputFile.writeAsStringSync(readLines[j], FileMode.append);

to this:

outputFile.writeAsStringSync(readLines[j], mode: FileMode.append);

Problem

I've got a text file (it has content in it) and I want to append text to it. This is my code: ``` File outputFile=new File('hello.out'); outputFile.createSync(); List<String> readLines=files[i].readAsLinesSync(Encoding.UTF_8); for(int j=0;j<readLines.length;j++) { outputFile.writeAsStringSync(readLines[j], FileMode.APPEND); } ``` For some reason Dart put a yellow line under "FileMode.APPEND" and it says that it's an "extra argument". However, this link http://api.dartlang.org/docs/releases/latest/dart_io/File.html claims that it is optional.

Original source