Golang io.Copy function example
package io
Golang io.Copy function usage example
package main
import (
"io"
"fmt"
"os"
)
func main () {
// open files r and w
r, err := os.Open("input.txt")
if err != nil {
panic(err)
}
defer r.Close()
w, err := os.Create("output.txt")
if err != nil {
panic(err)
}
defer w.Close()
// do the actual work
n, err := io.Copy(w, r) // <------ here !
if err != nil {
panic(err)
}
fmt.Printf("Copied %v bytes\n", n)
}
Reference :
Advertisement
Something interesting
Tutorials
+12.7k Golang : Pass database connection to function called from another package and HTTP Handler
+8.3k Golang : Auto-generate reply email with text/template package
+11.3k Golang : Byte format example
+11.6k Android Studio : Create custom icons for your application example
+21.2k Golang : How to get time zone and load different time zone?
+13.9k Golang : Get dimension(width and height) of image file
+18.5k Golang : Aligning strings to right, left and center with fill example
+7.6k Android Studio : AlertDialog to get user attention example
+12.2k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+11.6k Get form post value in Go
+8.2k Golang : Get final or effective URL with Request.URL example
+6.1k Golang : Dealing with backquote