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
+18.1k Golang : Execute shell command
+14.3k Golang : Delete certain files in a directory
+5k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+28.4k Golang : Get and Set User-Agent examples
+5.9k CloudFlare : Another way to get visitor's real IP address
+18.2k Golang : Delete item from slice based on index/key position
+10.9k Golang : Save webcamera frames to video file
+10.6k CodeIgniter : Import Linkedin data
+16.9k Golang : Check if a directory exist or not
+7.2k Golang : Reverse text lines or flip line order example
+6.8k Golang : How to execute code at certain day, hour and minute?
+9.2k Golang : cannot assign type int to value (type uint8) in range error