Standard library / bufio
bufio.NewReadWriter()
Combines a buffered reader and writer; flush its Writer separately after writes. Expected stdout: 'a\n'.
Formal Syntax & Structure
go syntaxgo
func NewReadWriter(r *Reader, w *Writer) *ReadWriterParameters & Attributes
| Name | Type | Description |
|---|---|---|
| r | *Reader | Source reader. |
| w | *Writer | Destination writer. |
Return Value
*ReadWriter
Combines a buffered reader and writer; flush its Writer separately after writes.
Working Example
Example Snippetgo
package main
import ( "bufio" "bytes" "fmt" "strings")
func main() { var b bytes.Buffer rw := bufio.NewReadWriter(bufio.NewReader(strings.NewReader("a")), bufio.NewWriter(&b)) x, _ := rw.ReadByte() rw.WriteByte(x) rw.Flush() fmt.Println(b.String())}