package main import ( "bufio" "fmt" "os" ) func main() { file, err := os.Create("test.txt") if err != nil { panic(err) } defer file.Close() writer := bufio.NewWriter(file) // Writing a single rune err = writer.WriteRune('A') if err != nil { panic(err) } writer.Flush() fmt.Println("File written successfully") }
package main import ( "bufio" "os" ) func main() { writer := bufio.NewWriter(os.Stdout) // Writing a single rune writer.WriteRune('G') // Writing a string writer.WriteString("o lang\n") writer.Flush() }This example demonstrates the use of the WriteRune function to write a single rune 'G' to the standard output (stdout) and also writes a string "Golang" followed by a new line character. In both examples, the bufio package is used to create a new writer object and the WriteRune function is used to write a single Unicode character to the buffer. The code is then flushed to the output (in example 2) or to the file (in example 1) using the Flush function.