Golang : Create Temporary File
Need to create a temporary file in Go? Easy. Below is the code in Go for creating a temporary file
package main
import (
"fmt"
"os"
"io/ioutil"
)
func main () {
file, err := ioutil.TempFile(os.TempDir(), "temp")
if err != nil {
panic(err)
}
fmt.Printf("Temp File created!")
defer os.Remove(file.Name())
}
Reference :
See also : Golang : Create 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
+22.9k Generate checksum for a file in Go
+9.7k Golang : Accessing content anonymously with Tor
+10.8k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+16.7k Golang : Get IP addresses of a domain name
+8.2k Golang : Get all countries phone codes
+7.3k Golang : Gorrila mux.Vars() function example
+15.1k Golang : How to check for empty array string or string?
+20.2k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+12.2k Golang : Convert a rune to unicode style string \u
+4.8k Javascript : Detect when console is activated and do something about it
+12.3k Golang : convert(cast) string to integer value
+6.2k PageSpeed : Clear or flush cache on web server