创建文件
通过os包的Create、NewFile方法创建
func Create(name string)(file *File,err Error)
func NewFile(fd uintprt,name string)*File
打开文件
func Open(name string)(file *File,err Error)
func OpenFile(name string,flag int,perm uint32)(file *File,err Error)
写文件
func (file *File) Write(b []byte)(n int,err Error)
func (file *File)WriteAt(b []byte,off int64)(n int,err Error)
func (file *File)WriteString(s string)(ret int,err Error)
读文件
func (file *File) Read(b []byte)(n int,err Error)
func (file *File)ReadAt(b []byte,off int64)(n int,err Error)
f,err := os.Create(path)
defer f.Close()
var buf string
buf = fmt.Sprintf("你好")
n,err := f.WriteString(buf)
f,err := os.Create(path)
defer f.Close()
buf := make([] byte,1024*2)
n,err := f.Read(buf)
var s string
s = string(buf[:n])
bufio 按给定规则读取文件
r := bufio.NewReader(f)
buf,err := r.ReadBytes('\n')
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Domain-Driven Design Distilled
Vaughn Vernon / Addison-Wesley Professional / 2016-6-2 / USD 36.99
Domain-Driven Design (DDD) software modeling delivers powerful results in practice, not just in theory, which is why developers worldwide are rapidly moving to adopt it. Now, for the first time, there......一起来看看 《Domain-Driven Design Distilled》 这本书的介绍吧!