golang读写文件内容
package main
import (
"fmt"
"io/ioutil"
)
func main() {
inputFile := "/golang/code/test1/src/day9/文件读写/input1"
output := "/golang/code/test1/src/day9/文件读写/output"
reader, err := ioutil.ReadFile(inputFile)
if err != nil {
fmt.Println("err: ", err)
return
}
fmt.Println("reader: ", string(reader))
err1 := ioutil.WriteFile(output, reader, 0777) // 写入文件内容,0777是创建的文件权限
if err1 != nil {
fmt.Println(err1)
}
}