Golang : Create Temporary File

Need to create a temporary file in Go? Easy. Below is the code in Go for creating a temporary file

 package main

 import (

 func main () {

 file, err := ioutil.TempFile(os.TempDir(), "temp")

 if err != nil {

 fmt.Printf("Temp File created!")

 defer os.Remove(file.Name())


Reference :


  See also : Golang : Create File

By Adam Ng

IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.