diff --git a/examples/reading-files/reading-files.go b/examples/reading-files/reading-files.go index bcff7fe..49387a6 100644 --- a/examples/reading-files/reading-files.go +++ b/examples/reading-files/reading-files.go @@ -40,7 +40,7 @@ func main() { b1 := make([]byte, 5) n1, err := f.Read(b1) check(err) - fmt.Printf("%d bytes: %s\n", n1, string(b1)) + fmt.Printf("%d bytes: %s\n", n1, string(b1[:n1])) // You can also `Seek` to a known location in the file // and `Read` from there. @@ -49,7 +49,8 @@ func main() { b2 := make([]byte, 2) n2, err := f.Read(b2) check(err) - fmt.Printf("%d bytes @ %d: %s\n", n2, o2, string(b2)) + fmt.Printf("%d bytes @ %d: ", n2, o2) + fmt.Printf("%v\n", string(b2[:n2])) // The `io` package provides some functions that may // be helpful for file reading. For example, reads @@ -80,5 +81,4 @@ func main() { // be scheduled immediately after `Open`ing with // `defer`). f.Close() - } diff --git a/examples/reading-files/reading-files.hash b/examples/reading-files/reading-files.hash index f687f38..8cf5bf6 100644 --- a/examples/reading-files/reading-files.hash +++ b/examples/reading-files/reading-files.hash @@ -1,2 +1,2 @@ -2aa7a2e248065cebfa6f8eece3234b5ffa710273 -GQgp-I3dLb2 +463a6f2999a023887af6b23c8f79f24978eb8115 +cocJ6kBH_iZ diff --git a/examples/reading-files/reading-files.sh b/examples/reading-files/reading-files.sh index b3ab74f..a1deb72 100644 --- a/examples/reading-files/reading-files.sh +++ b/examples/reading-files/reading-files.sh @@ -1,6 +1,6 @@ $ echo "hello" > /tmp/dat $ echo "go" >> /tmp/dat -$ go run reading-files.go +$ go run reading-files.go hello go 5 bytes: hello diff --git a/public/reading-files b/public/reading-files index 2e573cd..1b08728 100644 --- a/public/reading-files +++ b/public/reading-files @@ -29,7 +29,7 @@ reading files.
package main
b1 := make([]byte, 5)
n1, err := f.Read(b1)
check(err)
- fmt.Printf("%d bytes: %s\n", n1, string(b1))
+ fmt.Printf("%d bytes: %s\n", n1, string(b1[:n1]))
Read
from there.
b2 := make([]byte, 2)
n2, err := f.Read(b2)
check(err)
- fmt.Printf("%d bytes @ %d: %s\n", n2, o2, string(b2))
+ fmt.Printf("%d bytes @ %d: ", n2, o2)
+ fmt.Printf("%v\n", string(b2[:n2]))
@@ -214,22 +215,11 @@ reading methods it provides.
be scheduled immediately after Open
ing with
defer
).
-
- f.Close()
-
}
+ f.Close()
+}
Open
ing with
$ echo "hello" > /tmp/dat
$ echo "go" >> /tmp/dat
-$ go run reading-files.go
+$ go run reading-files.go
hello
go
5 bytes: hello