赞
踩
视频来源:B站《golang入门到项目实战 [2021最新Go语言教程,没有废话,纯干货!持续更新中...]》
一边学习一边整理老师的课程内容及试验笔记,并与大家分享,侵权即删,谢谢支持!
附上汇总贴:Go语言自学系列 | 汇总_COCOgsta的博客-CSDN博客
这里结束和File结构体相关的文件写操作
- package main
-
- import (
- "os"
- )
-
- // 写字节数组
- func write() {
- f, _ := os.OpenFile("a.txt", os.O_RDWR|os.O_APPEND, 0775)
- f.Write([]byte("hello golang"))
- f.Close()
- }
-
- // 写字符串
- func writeString() {
- f, _ := os.OpenFile("a.txt", os.O_RDWR|os.O_TRUNC, 0775)
- f.WriteString("hello world...")
- f.Close()
- }
-
- // 随机写
- func writeAt() {
- f, _ := os.OpenFile("a.txt", os.O_RDWR, 0775)
- f.WriteAt([]byte("aaa"), 3)
- f.Close()
- }
-
- func main() {
- // write()
- // writeString()
- writeAt()
- }
-

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。