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
+5k Golang : The Tao of importing package
+6.4k Golang : Derive cryptographic key from passwords with Argon2
+19.3k Golang : Set or Add HTTP Request Headers
+6.3k Unix/Linux : How to get own IP address ?
+12.3k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+10.1k Golang : Meaning of omitempty in struct's field tag
+5.9k Golang : Debug with Godebug
+7k Golang : How to detect if a sentence ends with a punctuation?
+8.8k Golang : Serving HTTP and Websocket from different ports in a program example
+6.9k CloudFlare : Another way to get visitor's real IP address
+5.8k Golang : Missing Subversion command
+14.1k Golang : On enumeration