go 缓冲IO

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	strReader := strings.NewReader("hello, world")
	bufReader := bufio.NewReader(strReader)
	//Peek: 提取不缓冲
	data, _ := bufReader.Peek(5)
	fmt.Println(string(data), bufReader.Buffered())
	//ReadString: 提取且缓冲
	str, _ := bufReader.ReadString(' ')
	fmt.Println(str, bufReader.Buffered())
	w := bufio.NewWriter(os.Stdout)
	fmt.Fprint(w, "Hello ")
	fmt.Fprint(w, "world!")
    //buffer一定要记得flush w.Flush() }

  

posted on 2019-06-21 11:21  清明-心若淡定  阅读(302)  评论(0编辑  收藏  举报