]> Cypherpunks repositories - gostls13.git/commitdiff
io/ioutil: add example for ReadFile
authorVitor De Mario <vitordemario@gmail.com>
Sat, 15 Jul 2017 17:25:37 +0000 (11:25 -0600)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sat, 15 Jul 2017 23:28:44 +0000 (23:28 +0000)
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>

src/io/ioutil/example_test.go
src/io/ioutil/testdata/hello [new file with mode: 0644]

index 0ccc92db840e4a65b7c4de86e6dbedd15cc854e3..53f71070d33d4109e31550d59ddabd643d69894e 100644 (file)
@@ -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 (file)
index 0000000..e47c092
--- /dev/null
@@ -0,0 +1 @@
+Hello, Gophers!