diff options
author | Vitor De Mario <vitordemario@gmail.com> | 2017-07-15 11:25:37 -0600 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2017-07-15 23:28:44 +0000 |
commit | 42aec4c03857a9bfcc8e445b2ae6abe1c7a055b4 (patch) | |
tree | 38ed6513e74ebc5c55cb089afdcc16144da6711a | |
parent | ced46c628877d9277a70c986467c1aff5f0b412c (diff) | |
download | go-42aec4c03857a9bfcc8e445b2ae6abe1c7a055b4.tar.gz go-42aec4c03857a9bfcc8e445b2ae6abe1c7a055b4.zip |
io/ioutil: add example for ReadFile
Change-Id: I062ec0606a741c8aa1b74f3f4b4e4fd47f76fed5
Reviewed-on: https://go-review.googlesource.com/48775
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
-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! |