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
+10.2k Golang : Channels and buffered channels examples
+10.8k Golang : Simple File Server
+6.6k Golang : How to search a list of records or data structures
+11.1k Golang : Removes punctuation or defined delimiter from the user's input
+30.1k Golang : Get and Set User-Agent examples
+8.5k Golang: Prevent over writing file with md5 hash
+14.6k Golang : Simple word wrap or line breaking example
+11.9k Golang : Secure file deletion with wipe example
+10.1k Golang : Convert octal value to string to deal with leading zero problem
+18.2k Golang : How to log each HTTP request to your web server?
+14.3k Javascript : Prompt confirmation before exit
+6.2k PageSpeed : Clear or flush cache on web server