How can I open files relative to my GOPATH?

前端 未结 4 785
忘掉有多难
忘掉有多难 2020-12-05 09:36

I\'m using io/ioutil to read a small text file:

fileBytes, err := ioutil.ReadFile(\"/absolute/path/to/file.txt\")

And that wor

4条回答
  •  旧巷少年郎
    2020-12-05 09:47

    this seems to work pretty well:

    import "os"
    import "io/ioutil"
    
    pwd, _ := os.Getwd()
    txt, _ := ioutil.ReadFile(pwd+"/path/to/file.txt")
    

提交回复
热议问题