Standard library / os
os.O_WRONLY
OpenFile access flag for writing only; does not itself truncate or create. Example uses a disposable temporary workspace. Expected stdout: 'Xbc\n'.
Formal Syntax & Structure
go syntaxgo
const O_WRONLY int = syscall.O_WRONLYWorking 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, 0) check(e) _, e = f.WriteString("X") check(e) check(f.Close()) b, e := os.ReadFile("a.txt") check(e) fmt.Println(string(b))}