Skip to content

Instantly share code, notes, and snippets.

@pyk
Created March 14, 2015 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyk/fe6d1bcd2a5095e5eade to your computer and use it in GitHub Desktop.
Save pyk/fe6d1bcd2a5095e5eade to your computer and use it in GitHub Desktop.
An example program that write data to a file in Go programming language. Learn more https://golang.kertaskampus.com/write-data-to-a-file/
package main
import (
"fmt"
"log"
"os"
)
func main() {
file, err := os.OpenFile("output.txt", os.O_RDWR, os.ModePerm)
if err != nil {
log.Fatal(err)
}
data := []byte("Example of data")
_, err = file.Write(data)
if err != nil {
log.Fatal(err)
}
fmt.Printf("write %q to output.txt\n", data)
}
Example of data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment