Created
July 29, 2020 10:22
-
-
Save maxwellgithinji/217a744a5f6f122b19602b0056f4cb1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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