Add error check to writing file

This commit is contained in:
andrew 2020-03-09 12:32:57 +02:00
parent 904c01a098
commit 7311e83283

View File

@ -40,6 +40,7 @@ func main() {
// A `WriteString` is also available. // A `WriteString` is also available.
n3, err := f.WriteString("writes\n") n3, err := f.WriteString("writes\n")
check(err)
fmt.Printf("wrote %d bytes\n", n3) fmt.Printf("wrote %d bytes\n", n3)
// Issue a `Sync` to flush writes to stable storage. // Issue a `Sync` to flush writes to stable storage.
@ -49,6 +50,7 @@ func main() {
// to the buffered readers we saw earlier. // to the buffered readers we saw earlier.
w := bufio.NewWriter(f) w := bufio.NewWriter(f)
n4, err := w.WriteString("buffered\n") n4, err := w.WriteString("buffered\n")
check(err)
fmt.Printf("wrote %d bytes\n", n4) fmt.Printf("wrote %d bytes\n", n4)
// Use `Flush` to ensure all buffered operations have // Use `Flush` to ensure all buffered operations have