There is a basic package:

package main import "testXML/dd" func main() { dd.SSS() } 

It connects to the package.

 ddfunc SSS() { bs, err := ioutil.ReadFile("dd/ff.conf") if err != nil { fmt.Println("--->", err) } str := string(bs) fmt.Println("::::::::::::::", str) } 

But is it possible to make the file read without a folder prefix, i.e. just "ff.conf"?

  • Describe in more detail what is where you are and how you launch the program. - rekby
  • Entry point to main application. It refers to the package attached to it and uses the function from the given package. Also in this package (dd), is the ff.conf file. I need to open ff.conf from a local directory. Without specifying the full path for the ReadFile function. I run it with the command: go run testXML / main.go; - Oma
  • And what is the context of use? If this is a temporary program for a one-time task, then what is the difference how it starts. If this is supposed to be distributed later, then this file is still not included in the compiled binary by default. Look at github.com/jteeuwen/go-bindata to include the file inside the final program. - rekby

1 answer 1

ioutil.ReadFile (filename) uses an absolute path. From here, the launch of the program will give the successful opening and reading of the file in a local directory, provided that there is a file with that name.

Errors can come up if you use different IDEs like IntelliJ IDEA which, when launched, compiles a temporary executable file into /tmp/рандомныйхашпроекта .