Standard library / os

os.O_APPEND

Requests appending writes rather than overwriting current bytes; WriteAt rejects append mode. Example uses a disposable temporary workspace. Expected stdout: 'abcd\n'.

Formal Syntax & Structure

go syntaxgo
const O_APPEND int = syscall.O_APPEND

Working Example

Example Snippetgo
package main
import (  "fmt"  "os")
func check(e error) {  if e != nil {    panic(e)  }}func seed() { check(os.WriteFile("a.txt", []byte("abc"), 0600)) }func workspace() func() {  root, e := os.MkdirTemp("", "bytemind-go-")  check(e)  old, e := os.Getwd()  check(e)  check(os.Chdir(root))  return func() { check(os.Chdir(old)); check(os.RemoveAll(root)) }}func main() {  defer workspace()()  seed()  f, e := os.OpenFile("a.txt", os.O_WRONLY|os.O_APPEND, 0)  check(e)  _, e = f.WriteString("d")  check(e)  check(f.Close())  b, e := os.ReadFile("a.txt")  check(e)  fmt.Println(string(b))}
Go Reference