Format and remove 07.5.md spaces
This commit is contained in:
110
zh/07.5.md
110
zh/07.5.md
@@ -23,22 +23,22 @@
|
||||
下面是演示代码:
|
||||
```Go
|
||||
|
||||
package main
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
os.Mkdir("astaxie", 0777)
|
||||
os.MkdirAll("astaxie/test1/test2", 0777)
|
||||
err := os.Remove("astaxie")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
os.RemoveAll("astaxie")
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
os.Mkdir("astaxie", 0777)
|
||||
os.MkdirAll("astaxie/test1/test2", 0777)
|
||||
err := os.Remove("astaxie")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
os.RemoveAll("astaxie")
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -84,26 +84,26 @@
|
||||
写文件的示例代码
|
||||
```Go
|
||||
|
||||
package main
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
userFile := "astaxie.txt"
|
||||
fout, err := os.Create(userFile)
|
||||
if err != nil {
|
||||
fmt.Println(userFile, err)
|
||||
return
|
||||
}
|
||||
defer fout.Close()
|
||||
for i := 0; i < 10; i++ {
|
||||
fout.WriteString("Just a test!\r\n")
|
||||
fout.Write([]byte("Just a test!\r\n"))
|
||||
}
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
userFile := "astaxie.txt"
|
||||
fout, err := os.Create(userFile)
|
||||
if err != nil {
|
||||
fmt.Println(userFile, err)
|
||||
return
|
||||
}
|
||||
defer fout.Close()
|
||||
for i := 0; i < 10; i++ {
|
||||
fout.WriteString("Just a test!\r\n")
|
||||
fout.Write([]byte("Just a test!\r\n"))
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
### 读文件
|
||||
@@ -120,31 +120,31 @@
|
||||
读文件的示例代码:
|
||||
```Go
|
||||
|
||||
package main
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
userFile := "asatxie.txt"
|
||||
fl, err := os.Open(userFile)
|
||||
if err != nil {
|
||||
fmt.Println(userFile, err)
|
||||
return
|
||||
}
|
||||
defer fl.Close()
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
n, _ := fl.Read(buf)
|
||||
if 0 == n {
|
||||
break
|
||||
}
|
||||
os.Stdout.Write(buf[:n])
|
||||
}
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
userFile := "asatxie.txt"
|
||||
fl, err := os.Open(userFile)
|
||||
if err != nil {
|
||||
fmt.Println(userFile, err)
|
||||
return
|
||||
}
|
||||
|
||||
defer fl.Close()
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
n, _ := fl.Read(buf)
|
||||
if 0 == n {
|
||||
break
|
||||
}
|
||||
os.Stdout.Write(buf[:n])
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
### 删除文件
|
||||
Go语言里面删除文件和删除文件夹是同一个函数
|
||||
|
||||
Reference in New Issue
Block a user