go ioutial 读取写入文件

 

package main

import (
	"fmt"
	"io/ioutil"
	"os"
)

func main() {
	// 读取文件
	//fileName := "./crawl/a.txt"
	//bytes, err := ioutil.ReadFile(fileName)
	//handError(err)
	//fmt.Printf("%s",string(bytes))

	// 写入内容
	content := "hello world 你好世界"
	err := ioutil.WriteFile("./crawl/b.txt", []byte(content), os.ModePerm)
	handError(err)
}

func handError(err error)  {
	if err != nil{
		fmt.Println(err)
	}
}

  

https://golang.google.cn/pkg/io/ioutil/#example_ReadFile

posted @ 2020-06-12 09:04  brady-wang  阅读(344)  评论(0编辑  收藏  举报