This answers works in Go1:
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
panic(err)
}
defer f.Close()
if _, err = f.WriteString(text); err != nil {
panic(err)
}
Related Contents:
- Write lines of text to a file in R
- What’s the de-facto way of reading and writing files in Rust 1.x?
- Ant: How to execute a command for each file in directory?
- Reading comment lines correctly in an input file using Fortran 90
- File I/O in a Linux kernel module
- File I/O in a Linux kernel module
- Write extracted data to a file using jmeter
- Too many arguments to return
- How to append text to an existing file in Java?
- Reading file contents on the client-side in javascript in various browsers
- Pointers vs. values in parameters and return values
- FileSystemWatcher vs polling to watch for file changes
- Hiding nil values, understanding why Go fails here
- What does go build build? (go build vs. go install)
- Does Go compiler’s evaluation differ for constant expression and other expression
- How to generate a random string of a fixed length in Go?
- What is the best way to slurp a file into a string in Perl?
- Why can’t I assign a *Struct to an *Interface?
- Java FileOutputStream Create File if not exists
- Trying to create a file in Android: open failed: EROFS (Read-only file system)
- file_put_contents – failed to open stream: Permission denied
- What are the Ruby File.open modes and options?
- Create file but if name exists add number
- Negative look-ahead in Go regular expressions
- If Go’s interfaces aren’t enforced, are they necessary?
- How can I define a struct field in my interface constraint (type T has no field or method)?
- Convert UTC string to time object
- How to escape back ticks
- How to create generic method in Go? (method must have no type parameters)
- “Operator does not exist: integer =?” when using Postgres
- How safe are Golang maps for concurrent Read/Write operations?
- golang how does the rune() function work
- “Unknown escape sequence” error in Go
- Golang defer behavior
- Using reflection to change static final File.separatorChar for unit testing?
- How to read text file from classpath in Java?
- Is there a way to convert integers to bools in go or vice versa?
- []byte(string) vs []byte(*string)
- Example for sync.WaitGroup correct?
- How to get the location of the DLL currently executing?
- How to decode JSON with type convert from string to float64
- Whats the difference of functions and methods in Go?
- Does Go have standard Err variables?
- How to parse JSON in golang without unmarshaling twice
- Partly JSON unmarshal into a map in Go
- checking for eof in string::getline
- Reading the last n lines of a file in Ruby?
- When do you embed mutex in struct in Go?
- Go doing a GET request and building the Querystring
- Go-compiled binary won’t run in an alpine docker container on Ubuntu host