英文:
How to read a tekst file during runtime
问题
你好,我有一个程序,我想要相对于安装在bin文件夹中的二进制文件读取文件。
我已经尝试使用以下方法:
filepath.Abs
os.Getwd()
但是这些方法只能给我返回当前运行时的"src"文件夹下的路径。
最终,我会使用:
os.Open(abspath)
你想要在运行时读取文件,该怎么做呢?
英文:
Hi I have a program where I want to read files relative to the binary installed in the bin folder.
I have looked at using:
filepath.Abs
os.Getwd()
But this only gives me the folder beneath "src" during.
<br>
<br>
<br>
Eventually I will use:
os.Open(abspath)
How do you read files during runtime?
答案1
得分: 2
我已经看过osext了,但是现在dyoo提到它,我去试了一下。而且它确实有效。
https://godoc.org/bitbucket.org/kardianos/osext
谢谢。
英文:
I had already seen the osext, but now that dyoo mentioned it - I went for it. And it works.
https://godoc.org/bitbucket.org/kardianos/osext
Thanks
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论