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
+15.6k Golang : Get file permission
+12.3k Golang : zlib compress file example
+5k Swift : Convert string array to array example
+19.1k Golang : How to count the number of repeated characters in a string?
+15k Golang : invalid character ',' looking for beginning of value
+25.9k Golang : Calculate future date with time.Add() function
+17.4k Golang : Login and logout a user after password verification and redirect example
+10.7k Golang : Roll the dice example
+15.6k Golang : Loop each day of the current month example
+5.7k Golang : Missing Subversion command
+6.8k Golang : How to iterate a slice without using for loop?