概述
名称 | 作用 | 备注 |
Reader | 实现了 io.Reader 的缓存 | |
Writer | 实现了 io.Writer 的缓存 | |
ReadWriter | 存储 *Reader *Writer,实现了 io.ReadWriter. | |
Scanner | 读取数据的便利的接口 |
示例
Writer
w := bufio.NewWriter(os.Stdout) fmt.Fprint(w, "Hello, ") fmt.Fprint(w, "world!") w.Flush() // Don't forget to flush! /* output: Hello, world! */
Scanner
scanner := bufio.NewScanner(os.Stdin) for scanner.Scan() { fmt.Println(scanner.Text()) // Println will add back the final '\n' } if err := scanner.Err(); err != nil { fmt.Fprintln(os.Stderr, "reading standard input:", err) }
有疑问加站长微信联系(非本文作者)