August 2019
Beginner to intermediate
798 pages
17h 2m
English
Going line by line is the most common method of reading a text file. This is the main reason that it is being shown first. The Go code of byLine.go, which will be presented in three parts, will help you to understand the technique.
The first code segment from byLine.go is shown in the following Go code:
package main
import (
"bufio"
"flag"
"fmt"
"io"
"os"
)
As you can see by the presence of the bufio package, we will use buffered input.
The second part of byLine.go contains the following Go code:
func lineByLine(file string) error { var err error f, err := os.Open(file) if err != nil { return err } defer f.Close() r := bufio.NewReader(f) for { line, err := r.ReadString('\n') if err == io.EOF { break } else ...Read now
Unlock full access