Ben Chuanlong Du's Blog

It is never too late to learn.

Create Temp Files and Directories in Golang

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

In [1]:
import "io/ioutil"
In [3]:
tempFile, err := ioutil.TempFile("", "example")
tempFile
Out[3]:
&{0xc00061c4e0}
In [6]:
tempFile.Name()
Out[6]:
/tmp/example3193020307
In [7]:
ioutil.TempDir("", "test*")
Out[7]:
/tmp/test2789120833<nil>
In [8]:
ioutil.TempDir("", "test")
Out[8]:
/tmp/test1160040211<nil>
In [ ]:
 

Comments