Skip to content

Instantly share code, notes, and snippets.

@dowens
Last active March 11, 2016 18:31
Show Gist options
  • Save dowens/e59ba00cd125614a6a37 to your computer and use it in GitHub Desktop.
Save dowens/e59ba00cd125614a6a37 to your computer and use it in GitHub Desktop.
read lines from file in Go
func readLine(path string) {
inFile, err := os.Open(path)
if err != nil {
log.Fatal(err)
}
defer inFile.Close()
scanner := bufio.NewScanner(inFile)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
fmt.Println(scanner.Text())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment