📅  最后修改于: 2022-03-11 14:45:00.242000             🧑  作者: Mango
package main
import (
"bufio"
"fmt"
"log"
"os"
)
func main() {
file, err := os.Open("/path/to/file.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
//! Inrease the buffer capacity if necessary
const maxCapacity = 10_000 * 1024 // 20GB == 20_000*1024
buf := make([]byte, maxCapacity)
scanner.Buffer(buf, maxCapacity)
// optionally, resize scanner's capacity for lines over 64K, see next example
for scanner.Scan() {
fmt.Println(scanner.Text())
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}