青春纸盒子

文: 芦苇

你喜欢我笑的样子

我靠上了落寞的窗子

晚风吹起了我的袖子

明月沾湿了你的眸子


转身,你走出了两个人的圈子

树影婆娑,整座院子


挽起袖子

回头,把揽你忧伤一地的影子

装进,青春,这纸盒子


更多代码请关注我的微信小程序: "ecoder"

luwei0915

导航

96_Go基础_1_64 bufio-write

 1 package main
 2 
 3 import (
 4     "bufio"
 5     "fmt"
 6     "os"
 7 )
 8 
 9 func main() {
10     /*
11         bufio:高效io读写
12             buffer缓存
13             io:input/output
14 
15         将io包下的Reader,Write对象进行包装,带缓存的包装,提高读写的效率
16 
17             func (b *Writer) Write(p []byte) (nn int, err error)
18             func (b *Writer) WriteByte(c byte) error
19             func (b *Writer) WriteRune(r rune) (size int, err error)
20             func (b *Writer) WriteString(s string) (int, error)
21 
22     */
23 
24     fileName := "D:\\Go\\web2\\aa.txt"
25     file, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY, os.ModePerm)
26     if err != nil {
27         fmt.Println(err)
28         return
29     }
30     defer file.Close()
31 
32     w1 := bufio.NewWriter(file)
33     // n, err := w1.WriteString("helloworld")
34     // fmt.Println(err)
35     // fmt.Println(n) // 10
36     // w1.Flush()     // 刷新缓冲区,即把缓冲区的数据写到文件
37 
38     for i := 1; i <= 1000; i++ {
39         w1.WriteString(fmt.Sprintf("%d:hello", i))
40     }
41     w1.Flush() // 缓冲区还有数据
42 }

 

posted on 2021-12-08 15:38  芦苇の  阅读(37)  评论(0编辑  收藏  举报