Writing to a File
This lesson provides code examples and their explanations for writing to a file.
We'll cover the following...
We'll cover the following...
Writing data to a file
Writing data to a file is demonstrated in the following program:
Apart from a filehandle, we now need a writer from bufio. We open a file output.dat for write-only at line 9. The file is created if it does not exist.
The os.OpenFile is a function that allows more control over the opening mode of a file. We see that the OpenFile function takes a filename, one or more flags (logically OR-d together using the | bitwise OR operator if more than one) and the file permissions to use.
The following flags ...