Go Package bufio: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 13: Line 13:
)
)


f, err := os.Open("/Users/ovidiu/tmp/adc.txt")
f, err := os.Open("/Users/ovidiu/tmp/sometext.txt")
if err != nil {
if err != nil {
   ...
   ...

Revision as of 23:27, 10 January 2024

External

Internal

Overview

Reading a Text File Line by Line

import (
	"bufio"
	"os"
)

f, err := os.Open("/Users/ovidiu/tmp/sometext.txt")
if err != nil {
  ...
}
defer f.Close()
scanner := bufio.NewScanner(f)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
  line := scanner.Text()
  ...
}