3000 explained code solutions for 75 technologies

golangHow to write text to file

package main

import (

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


include operating-system level library

[]byte("hello go!")

sample bytes to write to file


write specified content to given file


path to file to write content to


set file permissions after writing