Golang Program to Append Contents to Existing Text (TXT) File From Local File System Full Project For Beginners

  • Post author:
  • Post category:Go
  • Post comments:0 Comments

 

 

app.go

 

 

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)
}

Leave a Reply