为什么无法拷贝成功呢?

xmge · · 647 次点击
xmge
欲戴王冠 必承其重
谢谢大佬~~ 我解释一下啊,`io.WriteString(f1,"你好啊")` 将 f1 的游标放在了文件最后,再次读写时会从最后开始,所以没有拷贝成功。 ```go // Seek sets the offset for the next Read or Write on file to offset, interpreted // according to whence: 0 means relative to the origin of the file, 1 means // relative to the current offset, and 2 means relative to the end. // It returns the new offset and an error, if any. // The behavior of Seek on a file opened with O_APPEND is not specified. func (f *File) Seek(offset int64, whence int) (ret int64, err error) {} ```
#3
更多评论
xmge
欲戴王冠 必承其重
来...人...a
#1
polaris
社区,需要你我一同完善!
在 `fmt.Println(io.Copy(f2,f1))` 之前加上: `f1.Seek(0, os.SEEK_SET)`
#2