也可采用 ioutil 简洁读写文件
import (
"fmt"
"io"
"os"
)
func read() {
var filePath string = "C:\Users\Desktop\temp.txt"
fp, err := os.Open(filePath)
if err != nil {
fmt.Println(err)
}
defer fp.Close()
buff := make([]byte, 1024)
for {
len, err := fp.Read(buff)
if err == io.EOF || len < 0 {
break
}
fmt.Print(string(buff[:len]))
}
}