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
+23.9k Golang : Fix type interface{} has no field or no methods and type assertions example
+21.9k Golang : Use TLS version 1.2 and enforce server security configuration over client
+14k Golang : concatenate(combine) strings
+6.9k Mac OSX : Find large files by size
+8.2k Golang : Routes multiplexer routing example with regular expression control
+11.1k Golang : Read until certain character to break for loop
+17.2k Golang : Find file size(disk usage) with filepath.Walk
+7.1k Golang : Get environment variable
+6.7k Golang : When to use make or new?
+10.6k Golang : How to delete element(data) from map ?
+46.5k Golang : Marshal and unmarshal json.RawMessage struct example
+14.2k Golang : syscall.Socket example