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
+14.4k Golang : Parsing or breaking down URL
+28k Golang : Move file to another directory
+6.1k Golang : Missing Subversion command
+16.3k Golang : Loop each day of the current month example
+7.3k Golang : How to convert strange string to JSON with json.MarshalIndent
+12.3k Golang : Validate email address
+15k Golang : How do I get the local IP (non-loopback) address ?
+12.8k Golang : Convert int(year) to time.Time type
+31.9k Golang : Convert an image file to []byte
+9.4k Golang : Apply Histogram Equalization to color images
+9.1k Golang : Simple histogram example
+46.4k Golang : Encode image to base64 example