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
+37.1k Golang : Convert to io.ReadSeeker type
+18.4k Golang : Append content to a file
+17.2k Golang : Check whether a network interface is up on your machine
+7.2k Golang : How to check variable or object type during runtime?
+12.2k Golang : Set image canvas or background to transparent
+5.6k Golang : Check if password length meet the requirement
+8.6k Golang : Identifying Golang HTTP client request
+4.2k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+11.9k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+10.6k Golang : Gorilla web tool kit secure cookie example
+20.7k Golang : Securing password with salt