Skip to content

Append content to a file

The fs.open or File.open function is used to open a file and return a std.fs.File instance, with flag argument you can specify the file open mode.

  • The fs.APPEND flag is used to open the file in append mode.
  • The fs.CREATE flag is used to create a new file if the file does not exist.

Then use write_string method to write the string content to the file.

nv,

The above code will append the content to the file output.txt. If the file does not exist, it will create a new file.

After running the above code, the content of the file output.txt will be:

txt