// exists returns whether the given file or directory existsfunc 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}编辑以添加错误处理。

// exists returns whether the given file or directory existsfunc 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}编辑以添加错误处理。