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
+7.5k Golang : Reverse a string with unicode
+13.1k Golang : Verify token from Google Authenticator App
+9.9k Golang : Text file editor (accept input from screen and save to file)
+86.1k Golang : How to convert character to ASCII and back
+12.3k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+6.1k Golang : Selection sort example
+7.1k Golang : How to convert strange string to JSON with json.MarshalIndent
+9.2k Golang : Extract or copy items from map based on value
+5.9k Golang : Measure execution time for a function
+11.4k SSL : The certificate is not trusted because no issuer chain was provided
+7.5k Golang : Lock executable to a specific machine with unique hash of the machine
+9.9k Golang : Check a web page existence with HEAD request example