最近发布的主题
最近发布的文章
暂无
最近分享的资源
暂无
最近发布的项目
暂无
最近的评论
-
mike51@126.com
-
评论了主题 请高手回答闭包的问题?
-
评论了主题 io.copy在一个函数内为什么只能复制一次?多谢
-
评论了主题 io.copy在一个函数内为什么只能复制一次?
-
评论了主题 io.copy在一个函数内为什么只能复制一次?```go func main() { // Open a zip file for reading // 打开压缩文件包 zr, err := zip.OpenReader(filepath.Join( "D:/","Go WorkSpace/src/a_golearning_library_of_everything/go-packages/archive/zip/reader", "archive.zip")) if err != nil { log.Fatalln(err) } // Close the archive when we're done // 压缩完成后关闭 defer func() { if err := zr.Close(); err != nil { log.Fatalln(err) } }() // Iterate through the files in the archive // 循环逐个读取zip包内的文件 for _, f := range zr.File { // Open the current file to read it's contents // 打开包内的文件 rc, err := f.Open() if err != nil { log.Fatalln(err) } // Print the current file's name // 打印文件名 //fmt.Printf("%s:\n", f.Name) // Copy the contents of the file to stdout // 把文件内容输出到打印台 _, err = io.Copy(os.Stdout, rc) if err != nil { log.Fatalln(err) } fw,_:=os.Create(path.Join("D:/","Go WorkSpace/src/a_golearning_library_of_everything/go-packages/archive/zip/reader/",f.Name)) _,err = io.Copy(fw,rc) // Close the file handle // 关闭文件 if err := rc.Close(); err != nil { log.Fatalln(err) } fmt.Println("\n") } } ```