
configfile,err := os.Openfile("./version.Json",os.O_RDWR,0666)defer configfile.Close()check(err)//some actions happen hereconfigfile.Truncate(0)configfile.Write(Js)configfile.Sync() 结果,文件具有我在开头用0字节的部分写的内容.
如何在没有前导零的情况下截断并完全重写文件?
解决方法 请参阅Truncate上的文档:Truncate changes the size of the file. It does not change the I/O offset. If there is an error,it will be of type *PathError.
所以你还需要在写之前寻找文件的开头:
configfile.Truncate(0)configfile.Seek(0,0)总结
以上是内存溢出为你收集整理的在golang中截断文件全部内容,希望文章能够帮你解决在golang中截断文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)