Golang io.MultiWriter function example
package io
Golang io.MultiWriter function usage example
package main
import (
"fmt"
"io"
"os"
)
func main() {
writer, _ := os.Create("writer.dat")
writer2, _ := os.Create("writer2.dat")
mWriter := io.MultiWriter(writer, writer2)
data := []byte("Hello World!")
n, err := mWriter.Write(data)
if err == nil {
fmt.Printf("Multi write %d bytes to two files simultaneously.\n", n)
}
}
Output :
Multi write to 12 files simultaneously.
Reference :
Advertisement
Something interesting
Tutorials
+8.4k Golang : Convert word to its plural form example
+23.9k Golang : Use regular expression to validate domain name
+29.1k Golang : Get first few and last few characters from string
+4.1k Javascript : Empty an array example
+11.1k Golang : Simple image viewer with Go-GTK
+11k Golang : Generate random elements without repetition or duplicate
+7.4k Golang : Check to see if *File is a file or directory
+14.3k Golang : Simple word wrap or line breaking example
+9.2k Golang : Write multiple lines or divide string into multiple lines
+12.7k Golang : Add ASCII art to command line application launching process
+5.5k Golang : If else example and common mistake
+20.5k Golang : Pipe output from one os.Exec(shell command) to another command