go 读取文件
程序员文章站
2022-05-29 22:18:16
...
package main
import (
"fmt"
"io/ioutil"
"os"
)
func main() {
f, err := os.Open("test.txt")
if err != nil {
fmt.Println("read file fail", err)
panic(err)
}
defer f.Close()
fd, err := ioutil.ReadAll(f)
if err != nil {
fmt.Println("read to fd fail", err)
panic(err)
}
fmt.Println(string(fd))
}