forked from bsdplus/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo.notes
41 lines (35 loc) · 795 Bytes
/
go.notes
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
package main
//every independent package starts with this
import (
"fmt"
"os"
"log"
// "syscall"
)
// same as include <stdio.h> for those who knows C
func main() {
var input string
fmt.Print("Give a file to Open: ")
fmt.Scanf("%s",&input)
fmt.Println(input)
file, err := os.Open(input)
defer file.Close()
if err != nil {
//fmt.Println("Something goes wrong with the file man ...")
log.Fatal(err)
return
}
fd :=file.Fd()
fmt.Printf("File descriptor is %d\n",fd)
// this won't work, (my guess is that) Read takes
// an slice as argument instead of array
// var byte_array [50]byte
stat, err := file.Stat()
byte_array := make([]byte, stat.Size())
_, err = file.Read(byte_array)
if err != nil {
log.Fatal(err)
return
}
fmt.Println(string(byte_array))
}