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
+36.3k Golang : Convert(cast) int64 to string
+11.6k Golang : Fuzzy string search or approximate string matching example
+9k Golang : Inject/embed Javascript before sending out to browser example
+8.5k Golang : How to check if input string is a word?
+4.7k Chrome : How to block socketloop.com links in Google SERP?
+12.8k Golang : Convert int(year) to time.Time type
+5.2k PHP : See installed compiled-in-modules
+20.9k Golang : Underscore or snake_case to camel case example
+4.7k Unix/Linux : How to pipe/save output of a command to file?
+21.2k Golang : How to get time zone and load different time zone?
+17.6k Golang : Parse date string and convert to dd-mm-yyyy format
+22.4k Golang : How to read JPG(JPEG), GIF and PNG files ?