github.com/switchupcb/yaegi@v0.10.2/_test/file_access.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"os"
     7  )
     8  
     9  func main() {
    10  	file, err := ioutil.TempFile("", "yeagibench")
    11  	if err != nil {
    12  		panic(err)
    13  	}
    14  
    15  	n, err := file.Write([]byte("hello world"))
    16  	if err != nil {
    17  		panic(err)
    18  	}
    19  	fmt.Println("n:", n)
    20  
    21  	err = file.Close()
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  
    26  	b, err := ioutil.ReadFile(file.Name())
    27  	if err != nil {
    28  		panic(err)
    29  	}
    30  	fmt.Println("b:", string(b))
    31  
    32  	err = os.Remove(file.Name())
    33  	if err != nil {
    34  		panic(err)
    35  	}
    36  }
    37  
    38  // Output:
    39  // n: 11
    40  // b: hello world