read_write_file1.go 372 B

123456789101112131415161718192021
  1. // read_write_file.go
  2. package main
  3. import (
  4. "fmt"
  5. "io/ioutil"
  6. )
  7. func main() {
  8. inputFile := "products.txt"
  9. outputFile := "products_copy.txt"
  10. buf, err := ioutil.ReadFile(inputFile)
  11. if err != nil {
  12. panic(err.Error())
  13. }
  14. fmt.Printf("%s\n", string(buf))
  15. err = ioutil.WriteFile(outputFile, buf, 0x644)
  16. if err != nil {
  17. panic(err.Error())
  18. }
  19. }