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
+11.7k Get form post value in Go
+13.2k Golang : List objects in AWS S3 bucket
+9.8k Golang : Find correlation coefficient example
+15.4k Golang : Delete certain files in a directory
+13.8k Golang : Get user input until a command or receive a word to stop
+4.8k Javascript : Access JSON data example
+28.3k Golang : Connect to database (MySQL/MariaDB) server
+7.4k Golang : How to fix html/template : "somefile" is undefined error?
+7.4k Golang : File system scanning
+14.5k Golang : How to convert a number to words
+4.9k Fix Google Analytics Redundant Hostnames problem
+11.3k Golang : Fix go.exe is not compatible with the version of Windows you're running