fileName := "a.txt"
contents ,err := ioutil.ReadFile(fileName)
if err != nil{
fmt.Println("文件不存在")
}else{
fmt.Printf("%s
",contents)
}
fileName := "a.txt"
if contents ,err := ioutil.ReadFile(fileName);err!=nil{
fmt.Println("文件不存在")
}else{
fmt.Printf("%s
",contents)
}
go 语言的switch 默认会加break
var c = 2
switch c {
case 1 :
fmt.Print(c)
case 2:
fmt.Print("hello")
case 3:
fmt.Print("world")
default:
fmt.Println("this is the end")
switch 后面可以不跟表达式
var score = 80
switch {
case score >90 :
fmt.Print(score)
case score >80:
fmt.Print("hello")
case score >70:
fmt.Print("world")
default:
fmt.Println("this is the end")