io_test.go 340 B

12345678910111213141516171819
  1. package test
  2. import (
  3. "fmt"
  4. "io"
  5. "os"
  6. "testing"
  7. )
  8. func TestIO(t *testing.T) {
  9. //file, err := os.OpenFile("b.txt", os.O_RDONLY, 0)
  10. file, err := os.OpenFile("b.txt", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0)
  11. if err != nil {
  12. panic(err)
  13. }
  14. defer file.Close()
  15. contentBytes, err := io.ReadAll(file)
  16. fmt.Println(string(contentBytes))
  17. }