go-examples/example-file/main.go

33 lines
494 B
Go
Raw Normal View History

2017-07-07 12:29:36 +00:00
package main
import "fmt"
import "io"
import "io/ioutil"
import "log"
import "os"
import "strings"
var err *error
func readMe(r io.Reader) {
content, err := ioutil.ReadAll(r)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("%s\n", content)
}
func main() {
f, err := os.Open("/home/meutel/tmp/hello.txt")
if err != nil {
log.Fatalln(err)
}
defer f.Close()
fmt.Println(f.Name())
fmt.Println(f.Stat())
readMe(f)
strreader := strings.NewReader("c'est cool")
readMe(strreader)
}