Golang: Read an entire file

You need to import the 'io/ioutil' package for this.

	fileBytes, err := ioutil.ReadFile("/path/to/your/file")

This will return a slice of bytes as the first return argument, not a string.

You can convert it easily:

	fileAsString := string(fileBytes)
golang golang-io

Edit on github
comments powered by Disqus
Click me