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

原文地址:https://www.cnblogs.com/brady-wang/p/13097477.html