Browse Source

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

Lynn 7 months ago
parent
commit
5dca9dfcfd
1 changed files with 3 additions and 3 deletions
  1. 3 3
      eBook/12.7.md

+ 3 - 3
eBook/12.7.md

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