go read file to string 1

go read file to string

// go read file to string
b, err := ioutil.ReadFile("file.txt") // just pass the file name
    if err != nil {
        fmt.Print(err)
    }
str := string(b) // convert content to a 'string'

Here is what the above code is Doing:
1. Open the file.
2. Read the file.
3. Convert the file to a string.
4. Print the string.

Similar Posts