All Tools Bookmark

Share

http://www.online-toolz.com/howto/golang-how-to-read-a-file.php

Facebook Share Twitter Share

Golang how to read a file

The code snippets below shows Golang how to read a file




package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"log"
)

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


b, err := ioutil.ReadAll(file)
fmt.Print(b)
}
        
source