我想判断我的围棋代码中是否存在文件./conf/app.ini
,
但是我找不到一个好的方法来做到这一点.
我知道在Java:public boolean exists()
中有一个File方法,如果文件或目录存在,它将返回TRUE.
但是如何在围棋中做到这一点呢?
我想判断我的围棋代码中是否存在文件./conf/app.ini
,
但是我找不到一个好的方法来做到这一点.
我知道在Java:public boolean exists()
中有一个File方法,如果文件或目录存在,它将返回TRUE.
但是如何在围棋中做到这一点呢?
// exists returns whether the given file or directory exists
func exists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil { return true, nil }
if os.IsNotExist(err) { return false, nil }
return false, err
}
已编辑以添加错误处理.