Files
advent-of-code-2021/day-0/files.go
T

36 lines
532 B
Go
Raw Normal View History

2021-11-30 16:01:35 -05:00
package main
import (
"bufio"
"fmt"
"os"
)
func tryMe(e error) {
if e != nil {
fmt.Println("OH SNAP!")
panic(e)
}
}
func files() {
dat, err := os.ReadFile("./data.txt")
tryMe(err)
fmt.Print(string(dat))
fmt.Println("\n---")
f, err := os.Open("./data.txt")
tryMe(err)
coupleBytes := make([]byte, 10)
num, err := f.Read(coupleBytes)
tryMe(err)
fmt.Println(num, string(coupleBytes))
reader := bufio.NewReader(f)
rBuf, err := reader.Peek(5)
tryMe(err)
fmt.Println("buff reader", string(rBuf))
f.Close()
}