Created
March 14, 2015 07:13
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Example of data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment