Go 基础 ReadFile (6)

package main

import (
    "fmt"
    "io/ioutil"
)

func main()  {
    /*
    ReadFile 读取名为filename 文件内容,一次成功,的调用应当返回err= nil, 非 err==EOF
    EOF 来当作错误的报告
    */
    const filename = "a.txt"
    content,err := ioutil.ReadFile(filename)
    if err == nil {
        fmt.Printf("%s\n", content)
    } else {
        fmt.Print(err)
    }
}

 

posted @ 2020-10-13 15:31  Handsome、Snake  阅读(223)  评论(0编辑  收藏  举报