-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path11-files.go
47 lines (35 loc) · 875 Bytes
/
11-files.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
/*
* @Author: Barnabas Makonda
* @Date: 2019-01-15 22:46:46
* @Last Modified by: Barnabas Makonda
* @Last Modified time: 2019-01-15 22:46:46
*/
package main
import (
"fmt"
"io/ioutil"
"os"
)
/* Basic operations.
* Open- get handle for access
* Read - read bytes into []bytes
* Write - Write []byte into file
* Close - Release handle
* Seek - move read/write head
*/
func main() {
// data is []byte filled with contents of the entire file. using Readfile explicit open/close are not needed
// not feasible for large file
data, _ := ioutil.ReadFile("LICENCE")
dat := []byte("Hello, World")
_ = ioutil.WriteFile("out.txt", dat, 0777)
_ = ioutil.WriteFile("outed.txt", data, 0777)
// using os to open and reading
f, err := os.Open("out.txt")
barr := make([]byte, 10)
if err != nil {
nb, _ := f.Read(barr)
fmt.Println(nb)
}
f.Close()
}