Go: Read a whole file into a string (byte slice)
Use ioutil.ReadFile
in package io/ioutil
to read a whole file into a byte slice.
b, err := ioutil.ReadFile("file.txt") // b has type []byte
if err != nil {
log.Fatal(err)
}
str := string(b)
Comments
Be the first to comment!