package main
import (
"bufio"
"flag"
"fmt"
"io"
"log"
"os"
)
func main() {
fPath := flag.String("fPath", "src/tg_io/data.txt", "name of the file location to read")
flag.Parse()
f, err := os.Open(*fPath)
defer func() {
if err := f.Close(); err != nil {
log.Fatal(err)
}
}()
if err != nil {
log.Fatal(err)
}
r := bufio.NewReader(f)
b := make([]byte, 3)
for {
n, err := r.Read(b)
if err != nil {
if err != io.EOF {
log.Fatal(err)
} else {
fmt.Println("EOF recieved")
}
break
}
fmt.Printf("Read #bytes = %v. Data = %q \n", n, string(b[:n]))
}
// fmt.Println(string(*fPath))
}
Created
August 1, 2019 08:13
-
-
Save mannharleen/e2a04835d63cc849529ee08613b9aa24 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment