Golang io/ioutil.TempFile() function example
package io/ioutil
Golang io/ioutil.TempFile() function usage example
package main
import (
"fmt"
"io/ioutil"
)
func main() {
dir := "./"
prefix := "tempFileName"
file, err := ioutil.TempFile(dir, prefix)
if err != nil {
fmt.Println(err)
}
// TempFile will create a "new" file
// and you need to capture the name of the temp file
// to remove it later
fmt.Printf("%s \n", file.Name())
}
Reference :
Advertisement
Something interesting
Tutorials
+18.7k Golang : convert int to string
+4.7k Unix/Linux : How to pipe/save output of a command to file?
+4.8k PHP : Extract part of a string starting from the middle
+13.8k Golang : Gin framework accept query string by post request example
+15.9k Golang : Update database with GORM example
+4.4k Golang : Valued expressions and functions example
+7.4k Golang : Individual and total number of words counter example
+13.5k Facebook PHP getUser() returns 0
+6.6k Golang : Totalize or add-up an array or slice example
+11.2k Golang : How to pipe input data to executing child process?
+15.2k Golang : Get timezone offset from date or timestamp
+9.4k Golang : Web(Javascript) to server-side websocket example