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 (
"fmt"
"os"
"io/ioutil"
)
func main () {
file, err := ioutil.TempFile(os.TempDir(), "temp")
if err != nil {
panic(err)
}
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.
Advertisement
Tutorials
+7.9k Golang : automatically figure out array length(size) with three dots
+11.7k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+8.9k Golang : Convert octal value to string to deal with leading zero problem
+13.4k Golang : Get URI segments by number and assign as variable example
+4.9k Golang : Measure execution time for a function
+7.9k Golang : How to extract video or image files from html source code
+13.9k Golang : How to get Unix file descriptor for console and file
+19.3k Golang : Convert date string to variants of time.Time type examples
+3.8k Linux : How to set root password in Linux Mint
+6k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+37.4k Golang : Convert to io.ReadSeeker type
+8.9k Golang : Find and replace data in all files recursively