2020
12-22
12-22
golang逐行读取文件的操作
我就废话不多说了,大家还是直接看代码吧~funcReadLine(fileNamestring)([]string,error){f,err:=os.Open(fileName)iferr!=nil{returnnil,err}buf:=bufio.NewReader(f)varresult[]stringfor{line,err:=buf.ReadString('\n')line=strings.TrimSpace(line)iferr!=nil{iferr==io.EOF{//读取结束,会报EOFreturnresult,nil}returnnil,err}result=append(result,line...
继续阅读 >