5-1 文件读写-打开文件

package main


/*
以简易方式打开一个文件,一秒后关闭
以只读方式打开一个文件,创建起带缓冲的读取器,逐行读取到末尾。
使用ioutil包堆 文件进行简易读取
*/
import (
    "fmt"
    "os"
    "time"
)

func main() {

    file, e := os.Open("C:/Users/Administrator/Desktop/eth代币地址.txt")
    if e == nil{
        fmt.Println("文件打开成功" )
    }else{
        fmt.Println("文件打开失败,err=",e)
        //文件打开失败,直接返结果
        return
    }
    defer func() {
        file.Close()
        fmt.Println("文件关闭成功")
    }()

    time.Sleep(1*time.Second)
    fmt.Println("对文件进行操作",file)
}

 

posted @ 2019-06-27 19:54  pad+  阅读(171)  评论(0编辑  收藏  举报