golang文件相关的函数

func Create(name string) (file *File, err error) 直接通过纹面创建文件
func NewFile(fd uintptr, name string) *File
func Open(name string) (file *File, err error) 以只读方式打开一个存在的文件,打开就可以读取了。
func OpenFile(name string, flag int, perm FileMode) (file *File, err error)
func Pipe() (r *File, w *File, err error) 管道
func (f *File) Chdir() error 改变当前的工作目录
func (f *File) Chmod(mode FileMode) error 改变权限
func (f *File) Chown(uid, gid int) error 改变所有者
func (f *File) Close() error 关闭文件
func (f *File) Fd() uintptr 返回文件句柄
func (f *File) Name() string 返回文件名
func (f *File) Read(b []byte) (n int, err error) 读取文件
func (f *File) ReadAt(b []byte, off int64) (n int, err error) 从off开始读取文件
func (f *File) Readdir(n int) (fi []FileInfo, err error) 读取文件目录返回n个fileinfo
func (f *File) Readdirnames(n int) (names []string, err error) 读取文件目录返回n个文件名
func (f *File) Seek(offset int64, whence int) (ret int64, err error) 设置读写文件的偏移量,whence为0表示相对于文件的开始处,1表示相对于当前的位置,2表示相对于文件结尾。他返回偏移量。如果有错误返回错误
func (f *File) Stat() (fi FileInfo, err error) 返回当前文件fileinfo结构体
func (f *File) Sync() (err error) 把当前内容持久化,一般就是马上写入到磁盘
func (f *File) Truncate(size int64) error 改变当前文件的大小,他不改变当前文件读写的偏移量
func (f *File) Write(b []byte) (n int, err error) 写入内容
func (f *File) WriteAt(b []byte, off int64) (n int, err error) 在offset位置写入内容
func (f *File) WriteString(s string) (ret int, err error) 写入字符

猜你喜欢

转载自blog.csdn.net/u013235495/article/details/80507087
今日推荐