Temporary files are commonly used while running test cases or if your application needs to have a place to store short-term content such as user data uploads and currently processed data. This recipe will present the easiest way to create such a file or directory.
Creating temporary files
How to do it...
- Open the console and create the folder chapter06/recipe02.
- Navigate to the directory.
- Create the tempfile.go file with the following content:
package main
import "io/ioutil"
import "os"
import "fmt"
func main() {
tFile, err := ioutil.TempFile("", "gostdcookbook")
if err != nil {
panic(err)
}
...