上一页 1 2 3 4 5 6 7 8 9 ··· 12 下一页

2018年3月23日

6.9 文件内容对比

摘要: ```go package main import ( "bufio" "crypto/md5" "fmt" "io" "os" ) var data = []struct { name string cont string perm os.FileMode }{ {"test1.file", "Hello\nGolang is great", 0666}, {"test... 阅读全文

posted @ 2018-03-23 23:42 cucy_to 阅读(141) 评论(0) 推荐(0) 编辑

6.8 文件过滤

摘要: ```go package main import ( "fmt" "os" "path/filepath" ) func main() { for i := 1; i 阅读全文

posted @ 2018-03-23 23:40 cucy_to 阅读(95) 评论(0) 推荐(0) 编辑

6.7 创建目录

摘要: ```go package main import ( "os" ) func main() { f, err := os.Create("created.file") if err != nil { panic(err) } f.Close() f, err = os.OpenFile("created.byopen", os.O_CREATE|os.O_APPEND,... 阅读全文

posted @ 2018-03-23 23:38 cucy_to 阅读(80) 评论(0) 推荐(0) 编辑

6.6 修改文件权限

摘要: ```go package main import ( "fmt" "os" ) func main() { f, err := os.Create("test.file") if err != nil { panic(err) } defer f.Close() // Obtain current permissions fi, err := f.Stat() ... 阅读全文

posted @ 2018-03-23 23:36 cucy_to 阅读(124) 评论(0) 推荐(0) 编辑

6.5 列出当前目录所有文件

摘要: ```go package main import ( "fmt" "io/ioutil" "os" "path/filepath" ) func main() { fmt.Println("List by ReadDir") listDirByReadDir(".") fmt.Println() fmt.Println("List by Walk") listDirBy... 阅读全文

posted @ 2018-03-23 23:34 cucy_to 阅读(449) 评论(0) 推荐(1) 编辑

6.4 协程写文件

摘要: ```go package main import ( "fmt" "io" "os" "sync" ) type SyncWriter struct { m sync.Mutex Writer io.Writer } func (w *SyncWriter) Write(b []byte) (n int, err error) { w.m.Lock() defe... 阅读全文

posted @ 2018-03-23 23:31 cucy_to 阅读(272) 评论(0) 推荐(0) 编辑

6.3 写文件

摘要: ```go package main import ( "io" "os" "strings" ) func main() { f, err := os.Create("sample.file") if err != nil { panic(err) } defer f.Close() _, err = f.WriteString("Go is awesome!\n... 阅读全文

posted @ 2018-03-23 23:28 cucy_to 阅读(75) 评论(0) 推荐(0) 编辑

6.2 创建空目录

摘要: ```go package main import "io/ioutil" import "os" import "fmt" func main() { tFile, err := ioutil.TempFile("", "gostdcookbook") if err != nil { panic(err) } // The called is responsible for h... 阅读全文

posted @ 2018-03-23 23:26 cucy_to 阅读(224) 评论(0) 推荐(0) 编辑

6.1 os 获取文件状态

摘要: ```go package main import ( "fmt" "os" ) func main() { f, err := os.Open("test.file") if err != nil { panic(err) } fi, err := f.Stat() if err != nil { panic(err) } fmt.Printf("File n... 阅读全文

posted @ 2018-03-23 23:24 cucy_to 阅读(100) 评论(0) 推荐(0) 编辑

2018年3月22日

5.13 json

摘要: ```go package main import ( "encoding/json" "fmt" "strings" ) const js = ` [{ "name":"Axel", "lastname":"Fooley" }, { "name":"Tim", "lastname":"Burton 阅读全文

posted @ 2018-03-22 01:13 cucy_to 阅读(113) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 9 ··· 12 下一页

导航