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
+16.9k Golang : How to save log messages to file?
+10.8k Golang : Sieve of Eratosthenes algorithm
+10.1k Golang : Text file editor (accept input from screen and save to file)
+12k Golang : Detect user location with HTML5 geo-location
+19.3k Golang : How to count the number of repeated characters in a string?
+37.4k Upload multiple files with Go
+6.3k Golang : Selection sort example
+9.6k Random number generation with crypto/rand in Go
+7.3k Golang : How to convert strange string to JSON with json.MarshalIndent
+19.1k Golang : Calculate entire request body length during run time
+15.5k Golang : Validate hostname