Go program to add or append content at the end of text file
Example
package main
import (
"fmt"
"os"
)
func main() {
message := "Add this content at end"
filename := "test.txt"
f, err := os.OpenFile(filename, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
defer f.Close()
fmt.Fprintf(f, "%s\n", message)
}
Most Helpful This Week
Golang Create Copy of a file at another location
Golang Changing permissions, ownership, and timestamps
Get file information in Golang
Rename a file in Golang
Reduce file size
Go program to extracting or unzip a Zip format file
Golang program to delete a specific file
Go program to compress list of files into Zip file
Go program to read a text file character by character
Move a file from one location to another in Golang