-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
main.go
59 lines (43 loc) · 859 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
50
51
52
53
54
55
56
57
58
59
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
)
func cp(srcName, dstName string) error {
src, err := os.Open(srcName)
if err != nil {
return fmt.Errorf("error opening source file: %v", err)
}
defer src.Close()
dst, err := os.Create(dstName)
if err != nil {
return fmt.Errorf("error creating destination file:%v ", err)
}
defer dst.Close()
br := bufio.NewReader(src)
_, err = io.Copy(dst, br)
if err != nil {
return fmt.Errorf("error writing to destination file: %v ", err)
}
return nil
}
func main() {
if len(os.Args) < 3 {
log.Fatalln("Usage: 07_bufio_io-copy <SRC> <DST>")
}
srcName := os.Args[1]
dstName := os.Args[2]
err := cp(srcName, dstName)
if err != nil {
log.Fatalln(err)
}
}
/*
step 1 - at command line enter:
go install
step 2 - at command line enter:
programName initial.txt second.txt
*/