golang判断文件是否存在
package main
import (
"os"
"fmt"
)
func main(){
filepath := "/root/test.txt"
_,err := os.Stat(filepath)
if os.IsNotExist(err){
fmt.Println("file not exist")
return
}
fmt.Println("file exist")
}