package main
import (
"fmt"
"os"
)
func main() {
f:=createFile("D:\\webfront\\defer.txt")
defer closeFile(f)
writeFile(f)
}
func createFile(p string) *os.File{
fmt.Println("creating")
f,err :=os.Create(p)
if err!=nil {
panic(err)
}
return f
}
func writeFile(f *os.File){
fmt.Println("writing")
fmt.Fprintln(f,"data")
}
func closeFile(f *os.File){
fmt.Println("closing")
f.Close()
}
2、go Defer
凡事往简单处想,往认真处行
推荐阅读
- org.apache.hadoop.io.LongWritable cannot be cast to org.apache.hadoop.io.Text
- 使用JDBC方式连接ClickHouse查询数据
- Kubernetes入门(二)——Dashboard 安装
- No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK 问题解决
- EGADS介绍(一)--框架处理流程分析
- Zookeeper-3.5.8集群搭建
- EGADS介绍(二)--时序模型和异常检测模型算法的核心思想
- 如何实现一个高效的本地日志收集程序
- 时间序列分析(一)--移动平均
- Kubernetes入门(四)——如何在Kubernetes中部署一个可对外服务的Tensorflow机器学习模型