An easier way to learn how to use the Haxe core and related technologies.
Tagged with: Haxe
It's not obvious how to append to a file in Haxe. If you check the sys.io.File API, you'll find an append method, which looks promising, but outputs an instance of FileOutput
.
The FileOutput
API looks pretty sparse and unusable, until you click on the base-class Output
API. There, you see promising methods, like writeString
.
To combine these together, you can append a string to a file like so (don't forget to close the output stream):
public function append(message:String, fileName:String) {
var output:FileOutput = sys.io.File.append(fileName, false);
output.writeString(message);
output.close();
}