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
+27.6k PHP : Convert(cast) string to bigInt
+11.1k Golang : Read until certain character to break for loop
+16.8k Golang : read gzipped http response
+11k Golang : Create S3 bucket with official aws-sdk-go package
+22.5k Golang : Convert Unix timestamp to UTC timestamp
+15.3k Golang : How to get Unix file descriptor for console and file
+11.1k Golang : How to determine a prime number?
+8.6k Golang : Progress bar with ∎ character
+15.2k Golang : Accurate and reliable decimal calculations
+16.4k Golang : Test floating point numbers not-a-number and infinite example
+51.4k Golang : Check if item is in slice/array
+16.6k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file