请问大神,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")
}
}
```
#2
更多评论