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
+7.3k Golang : Calculate how many weeks left to go in a given year
+14.1k Javascript : Prompt confirmation before exit
+5.2k Golang : Experimental Jawi programming language
+5.4k Golang : What is StructTag and how to get StructTag's value?
+8.4k Golang : Ackermann function example
+12.1k Golang : Sort and reverse sort a slice of runes
+5.2k Responsive Google Adsense
+9.5k Golang : Accessing content anonymously with Tor
+8.7k Golang : How to join strings?
+18.3k Golang : Get path name to current directory or folder
+6.3k Golang : Detect face in uploaded photo like GPlus
+8.6k Golang : Add text to image and get OpenCV's X, Y co-ordinates example