我有一个使用config.json文件的Go应用程序来获取一些信息.当go run main.go它做它的工作,但当我将应用程序编译成可执行文件时,我有错误open config.json: no such file or directory.
我的代码是:
func main() {
data, err := ioutil.ReadFile("./config.json")
check(err)
var config config
err = json.Unmarshal(data, &config)
check(err)
}
Run Code Online (Sandbox Code Playgroud)
我也尝试了ioutil.ReadFile("config.json"),但它不起作用.check(err)并且config结构在main.go,问题不是来自这里.
main.go,config.json可执行文件位于同一目录中.
config.json编译程序后,如何才能使用该文件?