6.2 创建空目录


package main

import "io/ioutil"
import "os"
import "fmt"

func main() {
	tFile, err := ioutil.TempFile("", "gostdcookbook")
	if err != nil {
		panic(err)
	}
	// The called is responsible for handling
	// the clean up.
	defer os.Remove(tFile.Name())

	fmt.Println(tFile.Name())

	// TempDir returns
	// the path in string.
	tDir, err := ioutil.TempDir("", "gostdcookbookdir")
	if err != nil {
		panic(err)
	}
	defer os.Remove(tDir)
	fmt.Println(tDir)

}

/*
File name: test.file
Is Directory: false
Size: 18
Mode: -rwxr-xr-x
*/

posted on 2018-03-23 23:26  cucy_to  阅读(222)  评论(0编辑  收藏  举报

导航