1.IF判断(aa.txt内容:asdfgh。bb.txt内容:12345)
package main import ( "io/ioutil" "fmt" ) func main() { const filename1, filename2 = "aa.txt", "bb.txt" contents, err := ioutil.ReadFile(filename1) if err != nil { fmt.Println(err) } else{ fmt.Printf("%s\n", contents) } fmt.Printf("%s\n", contents) //打印出filename1的内容 if contents, err := ioutil.ReadFile(filename2);err != nil { fmt.Println(err) } else { fmt.Printf("%s\n", contents) } fmt.Printf("%s\n", contents) //还是打印出filename1的内容,filename2在if条件内,跳出IF之后失效(IP内部赋值,只对本次IF有效) }
打印结果;
asdfgh asdfgh 12345 asdfgh [Finished in 0.6s]
原文:https://www.cnblogs.com/vijayfly/p/9474847.html