Golang : Create File
Any sane programming language should have the basic File I/O functions. Luckily Go is one programming language in the sane category. We will show you how to create basic file in Go and more advance stuffs in the next couple of tutorials.
Ok, let's begin. Below is the code in Go for creating a file
package main
import (
"fmt"
"os"
)
func main () {
w, err := os.Create("output.txt")
if err != nil {
panic(err)
}
defer w.Close()
fmt.Printf("File created!)
}
References :
See also : Golang : Create Temporary File
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+15.5k Golang : How to generate QR codes?
+5.5k Android Studio : Hello World example
+5.8k Mac/Linux/Windows : Get CPU information from command line
+8.1k Golang : Play .WAV file from command line
+11.6k Golang : Pass database connection to function called from another package and HTTP Handler
+20.8k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+12k Golang : Date and Time formatting
+15.9k Golang : Get future or past hours, minutes or seconds
+6.6k Gogland : Single File versus Go Application Run Configurations
+23.7k Golang : Storing cookies in http.CookieJar example
+13.4k Golang : Submit web forms without browser by http.PostForm example
+19.8k Golang : Encrypt and decrypt data with TripleDES