golang从文件按行读取并输出
package main
import (
"fmt"
"os"
"bufio"
"io"
"time"
)
func main() {
file, err := os.Open("test.txt")
defer file.Close()
if nil == err {
buff := bufio.NewReader(file)
for {
line, err := buff.ReadString('\n')
if err == io.EOF {
break
}
fmt.Print(line)
time.Sleep(10*time.Millisecond)
}
}
}