Create a io.Reader from a local file

后端 未结 4 1447
悲哀的现实
悲哀的现实 2021-01-31 00:54

I would like to open a local file, and return a io.Reader. The reason is that I need to feed a io.Reader to a library I am using, like:



        
4条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 01:35

    os.Open returns an io.Reader

    http://play.golang.org/p/BskGT09kxL

    package main
    
    import (
        "fmt"
        "io"
        "os"
    )
    
    var _ io.Reader = (*os.File)(nil)
    
    func main() {
        fmt.Println("Hello, playground")
    }
    

提交回复
热议问题