天天看點

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())
  }      
abiStr, err := ioutil.ReadFile("router/nft/erc1155/abi")
  if err != nil {
    return "", fmt.Errorf("ioutil.ReadFile abi err:%v", err.Error())
  }