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.8k Golang : Gin framework accept query string by post request example
+16.6k Golang : Delete files by extension
+19.9k Golang : Count JSON objects and convert to slice/array
+5k Golang : Calculate a pip value and distance to target profit example
+21.4k Curl usage examples with Golang
+30k Golang : Get time.Duration in year, month, week or day
+18.4k Golang : How to get hour, minute, second from time?
+10.6k Golang : Simple File Server
+7.7k Golang : Generate human readable password