Golang 中逐行读取文件内容

原文地址声明:https://blog.csdn.net/qq_23179075/article/details/87082447

Golang 中通过 bufio.NewScanner() 逐行读取文件内容

package main

import (
	"bufio"
	"fmt"
	"os"
)
func ReadLineFile(fileName string) {
	if file, err := os.Open(fileName);err !=nil{
		panic(err)
	}else {
		scanner := bufio.NewScanner(file)
		for scanner.Scan(){
			fmt.Println(scanner.Text())
		}
	}
}

func main() {
	ReadLineFile("abc.txt")
}

你可能感兴趣的:(Go)