//f.Seek(0, 2)
出错了出错了,注释掉就没事了,centos 7.0
读取时err会等于EOF
出错了出错了,注释掉就没事了,centos 7.0
读取时err会等于EOF
2018-04-23
func (r *ReadFromFile) Read(rc chan []byte) {
//读取数据
f, err := os.Open(r.path)
if err != nil {
panic(fmt.Sprintf("open file fail:%s", err.Error()))
}
//从文件末尾逐行读取文件内容
f.Seek(0, 2)
rd := bufio.NewReader(f)
for {
line, err := rd.ReadBytes('\n')
if err == io.EOF {
log.Println(err)
time.Sleep(500 * time.Millisecond)
continue
} else if err != nil {
panic(fmt.Sprintf("ReadBytes error: %s", err.Error()))
}
rc <- line[:len(line)-1]
}
}如果注释不
f.Seek(0, 2)
则直接在
line, err := rd.ReadBytes('\n')err==io.EOF
举报