Create a io.Reader from a local file

后端 未结 4 1455
悲哀的现实
悲哀的现实 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条回答
  •  长情又很酷
    2021-01-31 01:22

    Use os.Open():

    func Open(name string) (file *File, err error)

    Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. If there is an error, it will be of type *PathError.

    The returned value of type *os.File implements the io.Reader interface.

提交回复
热议问题