Guest User

Untitled

a guest
Aug 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. ```go
  2. package main
  3.  
  4. import (
  5. "fmt"
  6. "io/ioutil"
  7. )
  8.  
  9. func main() {
  10.  
  11. mydata := []byte("All the data I wish to write to a file")
  12.  
  13. // the WriteFile method returns an error if unsuccessful
  14. err := ioutil.WriteFile("myfile.data", mydata, 0777)
  15. // handle this error
  16. if err != nil {
  17. // print it out
  18. fmt.Println(err)
  19. }
  20.  
  21. data, err := ioutil.ReadFile("myfile.data")
  22. if err != nil {
  23. fmt.Println(err)
  24. }
  25.  
  26. fmt.Print(string(data))
  27.  
  28. }
  29. ```
Add Comment
Please, Sign In to add comment