```go
package main
import (
"fmt"
"io"
"log"
"os"
)
func main() {
f1,err := os.Create("f1.txt")
if err != nil {
log.Fatal(err)
}
f2,err := os.Create("f2.txt")
if err != nil {
log.Fatal(err)
}
_,err = io.WriteString(f1,"你好啊")
if err != nil {
log.Fatal(err)
}
fmt.Println(io.Copy(f2,f1))
}
```
更多评论
谢谢大佬~~
我解释一下啊,`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