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.1k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+12.2k Golang : Get month name from date example
+6.6k Golang : When to use make or new?
+10.2k Golang : Convert file unix timestamp to UTC time example
+10.1k Golang : Text file editor (accept input from screen and save to file)
+5.5k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+6.2k Golang : Selection sort example
+27.2k Golang : Convert CSV data to JSON format and save to file
+8.2k Your page has meta tags in the body instead of the head
+7.1k Golang : Null and nil value
+19.1k Golang : Check if directory exist and create if does not exist
+7k Golang : Get environment variable