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
+6.7k Golang : Skip or discard items of non-interest when iterating example
+12.4k Golang : Display list of countries and ISO codes
+21.6k Golang : How to read float value from standard input ?
+24.1k Golang : Find biggest/largest number in array
+6.3k Golang : Calculate US Dollar Index (DXY)
+5.9k Golang : Launching your executable inside a console under Linux
+36.1k Golang : Get file last modified date and time
+6.9k Golang : Get expvar(export variables) to work with multiplexer
+17.8k Golang : delete and modify XML file content
+25.8k Golang : How to write CSV data to file
+12.9k Golang : Listen and Serve on sub domain example
+4.8k Unix/Linux : How to pipe/save output of a command to file?