9951 explained code solutions for 126 technologies

golangHow to append line to file

package main

import (

func main() {
	f, _ := os.OpenFile("/tmp/go.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
  defer f.Close()
  f.WriteString("new line\n")
}ctrl + c
package main

default package declaration


include operating-system level library

func main() {

declare main function that will be launched automatically


opens file handler


path to file to open


permissions used to append to file


file permissions to set

defer f.Close()

deferred file handler close


writes string to a given file