如何从大日志文件中读取最后两行而不将其完全加载到内存中?我需要每 10 秒阅读一次(在 Win 机器上)......我一直在试图阅读最后几行......package mainimport ( "fmt" "time" "os")const MYFILE = "logfile.log"func main() { c := time.Tick(10 * time.Second) for now := range c { readFile(MYFILE) }}func readFile(fname string){ file, err:=os.Open(fname) if err!=nil{ panic(err) } buf:=make([]byte, 32) c, err:=file.ReadAt(32, ????) fmt.Printf("%s\n", c)}日志文件类似于:07/25/2013 11:55:42.400, 0.55907/25/2013 11:55:52.200, 0.47707/25/2013 11:56:02.000, 0.46307/25/2013 11:56:11.800, 0.45407/25/2013 11:56:21.600, 0.42407/25/2013 11:56:31.400, 0.38207/25/2013 11:56:41.200, 0.35307/25/2013 11:56:51.000, 0.38407/25/2013 11:57:00.800, 0.39307/25/2013 11:57:10.600, 0.456谢谢!
3 回答
- 3 回答
- 0 关注
- 459 浏览
添加回答
举报
0/150
提交
取消