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
+29k Golang : JQuery AJAX post data to server and send data back to client example
+8k Prevent Write failed: Broken pipe problem during ssh session with screen command
+19.5k Golang : Measure http.Get() execution time
+7.3k Android Studio : AlertDialog to get user attention example
+27.7k Golang : Move file to another directory
+13.2k Golang : Get user input until a command or receive a word to stop
+7.5k Golang : How to execute code at certain day, hour and minute?
+7.6k Swift : Convert (cast) String to Double
+11.3k Golang : Simple file scaning and remove virus example
+5.1k Golang : Return multiple values from function
+6.5k Golang : Humanize and Titleize functions
+12k Golang : Flush and close file created by os.Create and bufio.NewWriter example