2948 explained code solutions for 75 technologies


golangHow to write text to file


package main

import (
	"os"
)

func main() {
	s := []byte("hello go!")
  os.WriteFile("/tmp/go.txt", s, 0755)
}ctrl + c
package main

default package declaration

func main() {

declare main function that will be launched automatically

"os"

include operating-system level library

[]byte("hello go!")

sample bytes to write to file

os.WriteFile

write specified content to given file

/tmp/go.txt

path to file to write content to

0755

set file permissions after writing