From: Vitor De Mario Date: Sat, 15 Jul 2017 17:25:37 +0000 (-0600) Subject: io/ioutil: add example for ReadFile X-Git-Tag: go1.9rc1~38 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=42aec4c03857a9bfcc8e445b2ae6abe1c7a055b4;p=gostls13.git 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 --- 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!