forked from GoesToEleven/GolangTraining
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
49 lines (37 loc) · 805 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"io/ioutil"
"log"
"os"
)
func main() {
if len(os.Args) < 3 {
log.Fatalln("Usage: 01_this-does-not-compile <SRC> <DST>")
}
srcName := os.Args[1]
dstName := os.Args[2]
src, err := os.Open(srcName)
if err != nil {
log.Fatalln("my program broke opening: ", err.Error())
}
defer src.Close()
dst, err := os.Create(dstName)
if err != nil {
log.Fatalln("my program broke creating: ", err.Error())
}
defer dst.Close()
bs, err := ioutil.ReadAll(src)
if err != nil {
log.Fatalln("my program broke reading: ", err.Error())
}
_, err = dst.Write(bs)
if err != nil {
log.Fatalln("my program broke writing: ", err.Error())
}
}
/*
step 1 - at command line enter:
go install
step 2 - at command line enter:
01_this-does-not-compile initial.txt second.txt
*/