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
|
```Go
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
os.Mkdir("astaxie", 0777)
|
os.Mkdir("astaxie", 0777)
|
||||||
os.MkdirAll("astaxie/test1/test2", 0777)
|
os.MkdirAll("astaxie/test1/test2", 0777)
|
||||||
err := os.Remove("astaxie")
|
err := os.Remove("astaxie")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
|
||||||
os.RemoveAll("astaxie")
|
|
||||||
}
|
}
|
||||||
|
os.RemoveAll("astaxie")
|
||||||
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -84,26 +84,26 @@
|
|||||||
写文件的示例代码
|
写文件的示例代码
|
||||||
```Go
|
```Go
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
userFile := "astaxie.txt"
|
userFile := "astaxie.txt"
|
||||||
fout, err := os.Create(userFile)
|
fout, err := os.Create(userFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(userFile, err)
|
fmt.Println(userFile, err)
|
||||||
return
|
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"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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
|
```Go
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
userFile := "asatxie.txt"
|
userFile := "asatxie.txt"
|
||||||
fl, err := os.Open(userFile)
|
fl, err := os.Open(userFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(userFile, err)
|
fmt.Println(userFile, err)
|
||||||
return
|
return
|
||||||
}
|
|
||||||
defer fl.Close()
|
|
||||||
buf := make([]byte, 1024)
|
|
||||||
for {
|
|
||||||
n, _ := fl.Read(buf)
|
|
||||||
if 0 == n {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
os.Stdout.Write(buf[:n])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
defer fl.Close()
|
||||||
|
buf := make([]byte, 1024)
|
||||||
|
for {
|
||||||
|
n, _ := fl.Read(buf)
|
||||||
|
if 0 == n {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
os.Stdout.Write(buf[:n])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
### 删除文件
|
### 删除文件
|
||||||
Go语言里面删除文件和删除文件夹是同一个函数
|
Go语言里面删除文件和删除文件夹是同一个函数
|
||||||
|
|||||||
Reference in New Issue
Block a user