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 Findstr command the Grep equivalent for Windows
+18.1k Golang : Check if a directory exist or not
+21.9k SSL : How to check if current certificate is sha1 or sha2
+7.7k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+6.9k Swift : substringWithRange() function example
+5.5k How to check with curl if my website or the asset is gzipped ?
+10.7k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+9.3k Golang : Create and shuffle deck of cards example
+7.1k Golang : Gargish-English language translator
+29.4k Golang : Save map/struct to JSON or XML file
+23.6k Golang : Read a file into an array or slice example