Skip to content

Instantly share code, notes, and snippets.

@maxwellgithinji
Created July 29, 2020 10:22
Show Gist options
  • Save maxwellgithinji/217a744a5f6f122b19602b0056f4cb1a to your computer and use it in GitHub Desktop.
Save maxwellgithinji/217a744a5f6f122b19602b0056f4cb1a to your computer and use it in GitHub Desktop.
//create a file `file-01.txt` in the same directory with some content to get started
package main
import (
"fmt"
"io"
"os"
)
func main() {
f, err := os.Open("file-01.txt")
if err != nil {
panic(err)
}
defer f.Close()
f2, err := os.Create("file-02.txt")
if err != nil {
panic(err)
}
defer f2.Close()
n, err := io.Copy(f2, f)
if err != nil {
panic(err)
}
fmt.Println("bytes written", n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment