This is the minimal example that writes a string (Hello World!
in this example) to a file (test.txt
in this example) using Go.
package main import "io/ioutil" func main() { content := "Hello World!" ioutil.WriteFile("test.txt", []byte(content), 0644) }
Note that this example:
- Creates the file with permission mode 0644, i.e. only the owner can write but others can read.
- Encodes the text as
UTF-8