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
+5.7k Golang : Frobnicate or tweaking a string example
+14.4k Golang : Parsing or breaking down URL
+9.1k Golang : Simple histogram example
+6.9k Golang : Normalize email to prevent multiple signups example
+12.5k Golang : Forwarding a local port to a remote server example
+9k Golang : Go as a script or running go with shebang/hashbang style
+13.3k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+11.2k Google Maps URL parameters configuration
+29.2k Golang : missing Git command
+6k Fontello : How to load and use fonts?
+31.7k Golang : How to convert(cast) string to IP address?
+12.6k Golang : Drop cookie to visitor's browser and http.SetCookie() example