golang The system cannot find the file specified
Posted 杰哥的技术杂货铺
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了golang The system cannot find the file specified相关的知识,希望对你有一定的参考价值。
使用io/ioutil包读取文件时报错:open abi: The system cannot find the file specified.
原因是:ioutil.ReadFile()
这个方法需要传入决绝路径的文件名
代码:
abiStr, err := ioutil.ReadFile("abi")
if err != nil
return "", fmt.Errorf("ioutil.ReadFile abi err:%v", err.Error())
ioutil.ReadFile(“abi”)
我之前认为需要读取的abi
文件,与代码文件在同一层目录,所以为绝对路径即可。但是经过证实,此处需要写绝对路径,即:
abiStr, err := ioutil.ReadFile("router/nft/erc1155/abi")
if err != nil
return "", fmt.Errorf("ioutil.ReadFile abi err:%v", err.Error())
以上是关于golang The system cannot find the file specified的主要内容,如果未能解决你的问题,请参考以下文章