Logo

Programming-Idioms

History of Idiom 138 > diff from v19 to v20

Edit summary for version 20 by programming-idioms.org:
[Go] pathname -> path string

Version 19

2019-10-07, 19:40:32

Version 20

2020-04-08, 16:26:01

Idiom #138 Create temp file

Create a new temporary file on filesystem.

Idiom #138 Create temp file

Create a new temporary file on filesystem.

Imports
import "io/ioutil"
Imports
import "io/ioutil"
Code
tmpfile, err := ioutil.TempFile("", "")
Code
tmpfile, err := ioutil.TempFile("", "")
Comments bubble
tmpfile has type *os.File.

Use tmpfile.Name() if you need the pathname.

Consider defer os.Remove(tmpfile.Name()) for cleanup.
Comments bubble
tmpfile has type *os.File.

Use tmpfile.Name() if you need the path string.

Consider defer os.Remove(tmpfile.Name()) for cleanup.
Doc URL
https://golang.org/pkg/io/ioutil/#TempFile
Doc URL
https://golang.org/pkg/io/ioutil/#TempFile
Demo URL
https://play.golang.org/p/CE0qLWoPL4
Demo URL
https://play.golang.org/p/CE0qLWoPL4