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
+9.4k Golang : Play .WAV file from command line
+48.1k Golang : How to convert JSON string to map and slice
+8.3k Golang : Configure Apache and NGINX to access your Go service example
+7.5k Golang : Rename part of filename
+7k Golang : Gargish-English language translator
+5.9k Golang : Denco multiplexer example
+9.2k Golang : Write multiple lines or divide string into multiple lines
+31.5k Golang : bufio.NewReader.ReadLine to read file line by line
+37.5k Golang : Converting a negative number to positive number
+6.8k Get Facebook friends working in same company
+11.2k CodeIgniter : How to check if a session exist in PHP?
+23.1k Golang : simulate tail -f or read last line from log file example