为什么如果我 print bs
,在调用之前Read()
,它什么也不打印,但是在调用之后file.Read(bs)
,它显示了 test.txt 文件的内部。除非bs
只是论据,怎么Read()
可能改变呢?
package main
import (
"os"
"fmt"
)
func main() {
file , err := os.Open("test.txt")
if err == nil {
} else {
}
stat , _ := file.Stat()
bs := make([]byte, stat.Size())
fmt.Println(string(bs))
bsf ,err := file.Read(bs)
if err != nil{
fmt.Println(err)
fmt.Println(bsf)
}
fmt.Println(string(bs))
}
输出:
(Line1)
(Line2)hi, This is Example text in test.txt file.