Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Read file as one string (slurp)

  • ReadFile
  • slurp
package main

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

func main() {
	filename := "slurp_file.go"
	dat, err := ioutil.ReadFile(filename)
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		os.Exit(1)
	}
	fmt.Println(string(dat))
}