diff options
-rw-r--r-- | src/io/ioutil/example_test.go | 12 | ||||
-rw-r--r-- | src/io/ioutil/testdata/hello | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/io/ioutil/example_test.go b/src/io/ioutil/example_test.go index 0ccc92db84..53f71070d3 100644 --- a/src/io/ioutil/example_test.go +++ b/src/io/ioutil/example_test.go @@ -69,3 +69,15 @@ func ExampleTempFile() { log.Fatal(err) } } + +func ExampleReadFile() { + content, err := ioutil.ReadFile("testdata/hello") + if err != nil { + log.Fatal(err) + } + + fmt.Printf("File contents: %s", content) + + // Output: + // File contents: Hello, Gophers! +} diff --git a/src/io/ioutil/testdata/hello b/src/io/ioutil/testdata/hello new file mode 100644 index 0000000000..e47c092a51 --- /dev/null +++ b/src/io/ioutil/testdata/hello @@ -0,0 +1 @@ +Hello, Gophers! |