33 lines
494 B
Go
33 lines
494 B
Go
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)
|
|
}
|