package main import ( "bufio" "os" ) func main() { // Create a new file file, err := os.Create("output.txt") if err != nil { panic(err) } defer file.Close() // Create a new bufio writer writer := bufio.NewWriter(file) // Write a string to the file writer.WriteString("Hello, world!\n") // Flush the contents to the file writer.Flush() }
package main import ( "bufio" "os" ) func main() { // Create a new file file, err := os.Create("output.txt") if err != nil { panic(err) } defer file.Close() // Create a new bufio writer writer := bufio.NewWriter(file) // Write multiple strings to the file writer.WriteString("Hello, ") writer.WriteString("world!\n") // Flush the contents to the file writer.Flush() }In this example, we create a new file named `output.txt` and create a new bufio writer. We then use the WriteString method twice to write two different strings to the file. Finally, we flush the contents to the file using the Flush method.