package main import ( "bufio" "fmt" "io" "os" ) func lineByLine(file string) 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 { if len(line) != 0 { fmt.Println(line) } break } if err != nil { fmt.Printf("error reading file %s\n", err) return err } fmt.Print(line) } return nil } func main() { lineByLine("data.csv") }
zzh@ZZHPC:/zdata/Github/ztest$ go run main.go Dimitris,Tsoukalos,2101112223,1600665563 Mihalis,Tsoukalos,2109416471,1600665563 Jane,Doe,0800123456,1608559903
标签:Files,return,err,Read,fmt,file,Zgo,line,main From: https://www.cnblogs.com/zhangzhihui/p/18243520