Golang bufio.NewScanner() function example

package bufio

NewScanner returns a new Scanner to read from. The split function defaults to ScanLines.

Golang bufio.NewScanner() function usage example

 package main

 import (
 "fmt"
 "os"
 "bufio"
 )

 func main () {
 file, err := os.Open("for")

 if err != nil {
 panic(err.Error())
 }

 defer file.Close()

 reader := bufio.NewReader(file)
 scanner := bufio.NewScanner(reader)

 scanner.Split(bufio.ScanBytes)

 for scanner.Scan() {
 fmt.Println(scanner.Bytes())
 }
 }

Advertisement