Skip to content

Instantly share code, notes, and snippets.

@johnwesonga
Created August 22, 2013 00:23
Show Gist options
  • Save johnwesonga/6301883 to your computer and use it in GitHub Desktop.
Save johnwesonga/6301883 to your computer and use it in GitHub Desktop.
Read file in Go using ioutil
package main
import (
"fmt"
"io/ioutil"
"strings"
)
func main() {
f, err := ioutil.ReadFile("sample.txt")
if err != nil {
fmt.Printf("error %v\n", err)
return
}
wordSlice := strings.Split(string(f), "\n")
fmt.Println(wordSlice)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment