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
+23.2k Golang : Print out struct values in string format
+19.9k Golang : Count JSON objects and convert to slice/array
+12.8k Golang : Convert int(year) to time.Time type
+22.6k Generate checksum for a file in Go
+31.1k Golang : Calculate percentage change of two values
+8.8k Android Studio : Image button and button example
+7.7k Gogland : Where to put source code files in package directory for rookie
+62.7k Golang : Convert HTTP Response body to string
+12.7k Golang : Pass database connection to function called from another package and HTTP Handler
+18.8k Golang : How to make function callback or pass value from function as parameter?
+26.3k Golang : Calculate future date with time.Add() function
+25.7k Golang : missing Mercurial command