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
+20k Golang : Convert(cast) string to rune and back to string example
+22k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+5k Golang : Dealing with backquote
+4.7k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+23.6k Golang : Storing cookies in http.CookieJar example
+6.9k Golang : How to feed or take banana with Gorilla Web Toolkit Session package
+3.4k Javascript : Detect when console is activated and do something about it
+6.4k Golang : Rename part of filename
+8k Golang : How to check if a string with spaces in between is numeric?
+5.4k Android Studio : Hello World example
+13.3k Golang : Save(pipe) HTTP response into a file