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.6k Golang : Generate random integer or float number
+8.7k Golang : Copy map(hash table) example
+2.8k Java : Get FX sentiment from website example
+38k Golang : How to read CSV file
+8.1k Golang : Handle sub domain with Gin
+18.6k Golang : Measure http.Get() execution time
+10.5k Golang : Byte format example
+7.8k Golang : On lambda, anonymous, inline functions and function literals
+5.2k Golang : How to verify input is rune?
+3.8k Linux/MacOSX : Search and delete files by extension
+4.5k Golang : The Tao of importing package
+7k Golang : Get today's weekday name and calculate target day distance example