package main import ( "bufio" "os" ) func main() { w := bufio.NewWriter(os.Stdout) w.WriteByte('A') w.Flush() }
package main import ( "bufio" "os" ) func main() { inFile, _ := os.Open("input.txt") defer inFile.Close() outFile, _ := os.Create("output.txt") defer outFile.Close() reader := bufio.NewReader(inFile) writer := bufio.NewWriter(outFile) for { b, err := reader.ReadByte() if err != nil || err == io.EOF { break } writer.WriteByte(b) } writer.Flush() }In this example, we read from an input file one byte at a time using a bufio.NewReader instance. We then create a new file using os.Create and a new Writer instance using bufio.NewWriter, passing in the output file as its underlying output stream. We then loop through each byte read, using WriteByte to write it to the output file. Finally, we call Flush on the writer to ensure any remaining buffered data is written to the output file. Overall, the bufio.Writer package provides a simple and efficient way to perform buffered writing operations in Go.