修改defer关闭文件代码片段中的错误 (#403)

This commit is contained in:
Lynn
2017-10-13 04:08:33 -05:00
committed by 无闻
parent 31b37916b3
commit 5dca9dfcfd

View File

@@ -4,10 +4,10 @@
```go
func data(name string) string {
f := os.Open(name, os.O_RDONLY, 0)
f, _ := os.OpenFile(name, os.O_RDONLY, 0)
defer f.Close() // idiomatic Go code!
contents := io.ReadAll(f)
return contents
contents, _ := ioutil.ReadAll(f)
return string(contents)
}
```