Skip to content

Instantly share code, notes, and snippets.

@thedevsaddam
Forked from pagoenka/ReadFile.go
Created January 16, 2017 05:20
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save thedevsaddam/d7eff4608e2b41e2d8bc2b734183ede9 to your computer and use it in GitHub Desktop.
Save thedevsaddam/d7eff4608e2b41e2d8bc2b734183ede9 to your computer and use it in GitHub Desktop.
Reading file, line by line in Go lang using scanner
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
fileHandle, _ := os.Open("file_name.txt")
defer fileHandle.Close()
fileScanner := bufio.NewScanner(fileHandle)
for fileScanner.Scan() {
fmt.Println(fileScanner.Text())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment