mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-11-13 17:36:12 +08:00
update book code
This commit is contained in:
21
eBook/examples/chapter_12/read_write_file1.go
Normal file
21
eBook/examples/chapter_12/read_write_file1.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// read_write_file.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
inputFile := "products.txt"
|
||||
outputFile := "products_copy.txt"
|
||||
buf, err := ioutil.ReadFile(inputFile)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
fmt.Printf("%s\n", string(buf))
|
||||
err = ioutil.WriteFile(outputFile, buf, 0x644)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user