Skip to content

Instantly share code, notes, and snippets.

@arschles
Created July 15, 2015 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arschles/6523b48f1c393ae9aa0e to your computer and use it in GitHub Desktop.
Save arschles/6523b48f1c393ae9aa0e to your computer and use it in GitHub Desktop.
golang read a file line by line
import (
"bufio"
"os"
)
func main() {
f := os.Open("somefile")
defer f.Close
rdr := bufio.NewReader(f)
for {
// I'm assuming it's ok to assume lines are newline-terminated
line, err := rdr.ReadString("\n")
if err != nil {
break
}
//do something with line
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment