How to read a text file?

Viewed 146161

I'm trying to read "file.txt" and put the contents into a variable using Golang. Here is what I've tried...

package main

import (
    "fmt"
    "os"
    "log"
)

func main() {
    file, err := os.Open("file.txt")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Print(file)
}

The file gets read successfully and the return from os.Open returns a type of *os.File

1 Answers
Related