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
+9.9k Golang : Text file editor (accept input from screen and save to file)
+17.7k Golang : How to log each HTTP request to your web server?
+29.2k Golang : Login(Authenticate) with Facebook example
+10.6k Golang : Natural string sorting example
+34.7k Golang : Upload and download file to/from AWS S3
+8k Swift : Convert (cast) Character to Integer?
+5.5k Fix yum-complete-transaction error
+28.4k Golang : Detect (OS) Operating System
+31.7k Golang : Validate email address with regular expression
+30.9k Golang : bufio.NewReader.ReadLine to read file line by line
+12.4k Golang : Listen and Serve on sub domain example
+7.7k Golang : Sort words with first uppercase letter