1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
18 func ExampleReadAll() {
19 r
:= strings
.NewReader("Go is a general-purpose language designed with systems programming in mind.")
21 b
, err
:= ioutil
.ReadAll(r
)
29 // Go is a general-purpose language designed with systems programming in mind.
32 func ExampleReadDir() {
33 files
, err
:= ioutil
.ReadDir(".")
38 for _
, file
:= range files
{
39 fmt
.Println(file
.Name())
43 func ExampleTempDir() {
44 content
:= []byte("temporary file's content")
45 dir
, err
:= ioutil
.TempDir("", "example")
50 defer os
.RemoveAll(dir
) // clean up
52 tmpfn
:= filepath
.Join(dir
, "tmpfile")
53 if err
:= ioutil
.WriteFile(tmpfn
, content
, 0666); err
!= nil {
58 func ExampleTempFile() {
59 content
:= []byte("temporary file's content")
60 tmpfile
, err
:= ioutil
.TempFile("", "example")
65 defer os
.Remove(tmpfile
.Name()) // clean up
67 if _
, err
:= tmpfile
.Write(content
); err
!= nil {
70 if err
:= tmpfile
.Close(); err
!= nil {
75 func ExampleReadFile() {
76 content
, err
:= ioutil
.ReadFile("testdata/hello")
81 fmt
.Printf("File contents: %s", content
)
84 // File contents: Hello, Gophers!