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
+6.7k Golang : Humanize and Titleize functions
+8.4k Golang : Generate Datamatrix barcode
+19.9k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+4.9k JQuery : Calling a function inside Jquery(document) block
+7.2k Golang : Check if one string(rune) is permutation of another string(rune)
+9.7k Golang : interface - when and where to use examples
+18.4k Golang : How to remove certain lines from a file
+26.7k Golang : How to check if a connection to database is still alive ?
+6.3k Golang : Detect face in uploaded photo like GPlus
+13.1k Golang : Handle or parse date string with Z suffix(RFC3339) example
+12.1k Golang : convert(cast) string to integer value