package main
import (
"io/ioutil"
"log"
"os"
"time"
)
func main() {
f, err := os.OpenFile("/tmp/tmp_file", os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
if err != nil {
log.Fatal(err)
}
defer f.Close()
defer os.Remove(f.Name())
b, err := ioutil.ReadAll(f)
if err != nil {
log.Fatal(err)
}
log.Printf("content: %s\n", string(b))
time.Sleep(1 * time.Minute)
f.Seek(0, 0)
b, err = ioutil.ReadAll(f)
if err != nil {
log.Fatal(err)
}
log.Printf("new content: %s\n", string(b))
}
Mac 下面会
有疑问加站长微信联系(非本文作者)