From 42aec4c03857a9bfcc8e445b2ae6abe1c7a055b4 Mon Sep 17 00:00:00 2001 From: Vitor De Mario Date: Sat, 15 Jul 2017 11:25:37 -0600 Subject: io/ioutil: add example for ReadFile Change-Id: I062ec0606a741c8aa1b74f3f4b4e4fd47f76fed5 Reviewed-on: https://go-review.googlesource.com/48775 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/io/ioutil/example_test.go | 12 ++++++++++++ src/io/ioutil/testdata/hello | 1 + 2 files changed, 13 insertions(+) create mode 100644 src/io/ioutil/testdata/hello 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! -- cgit v1.2.3-54-g00ecf