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
+13.4k Golang : Increment string example
+24.5k Golang : GORM read from database example
+6.2k Golang : Extract XML attribute data with attr field tag example
+15.4k Golang : invalid character ',' looking for beginning of value
+4.9k Nginx and PageSpeed build from source CentOS example
+30.5k Golang : Generate random string
+21.6k Golang : Encrypt and decrypt data with TripleDES
+22.5k Golang : Convert Unix timestamp to UTC timestamp
+7.7k Golang : Mapping Iban to Dunging alphabets
+15.6k Golang : ROT47 (Caesar cipher by 47 characters) example
+39k Golang : How to iterate over a []string(array)
+21.4k Curl usage examples with Golang