使用
ioutil.ReadFile:
原文链接:https://www.f2er.com/go/188143.htmlfunc ReadFile(filename string) ([]byte,error)
ReadFile reads the file named by filename and returns the contents. A successful call
returns err == nil,not err == EOF. Because ReadFile reads the whole file,it does not treat
an EOF from Read as an error to be reported.
你会得到一个[]字节而不是字符串。如果真的有必要可以转换:
s := string(buf)