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
+8.1k Golang : Create and shuffle deck of cards example
+4.2k Golang : Pad file extension automagically
+17.3k Golang : Get path name to current directory or folder
+12.5k Golang : Reverse IP address for reverse DNS lookup example
+6.7k Golang : How to execute code at certain day, hour and minute?
+8.7k Golang : Sort and reverse sort a slice of floats
+11.1k Golang : convert(cast) string to integer value
+12.8k Golang : Simple word wrap or line breaking example
+24.8k Golang : Convert(cast) string to uint8 type and back to string
+13.6k Golang : Search folders for file recursively with wildcard support
+16.3k Golang : Login and logout a user after password verification and redirect example
+14.9k Golang : convert string or integer to big.Int type