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
+9.3k Golang : Populate slice with sequential integers example
+12.3k Golang : zlib compress file example
+6.2k Elasticsearch : Shutdown a local node
+15.2k Golang : Validate hostname
+38.6k Golang : How to iterate over a []string(array)
+6.8k Golang : Array mapping with Interface
+31.2k Golang : Convert an image file to []byte
+17.1k Golang : Clone with pointer and modify value
+13.5k Golang : Reverse IP address for reverse DNS lookup example
+14k Golang : Parsing or breaking down URL
+9.3k Golang : Copy map(hash table) example
+8.5k Golang : GMail API create and send draft with simple upload attachment example