package main
import (
"bufio"
"fmt"
"io"
"os"
)
func main() {
filepath := "d:/zzf.txt"
//文件的操作权限赋予
file, err := os.OpenFile(filepath, os.O_RDWR|os.O_APPEND, 0666)
if err != nil {
return
}
defer file.Close()
//获取读的流
reader := bufio.NewReader(file)
for {
str, error := reader.ReadString('\n')
if error == io.EOF {
break
}
fmt.Println(str)
}
strs := "zzf\n"
//获取写的流
write := bufio.NewWriter(file)
write.WriteString(strs)
//记得最后flus
write.Flush()
}
golang文件读写数据
最新推荐文章于 2024-11-06 22:02:44 发布