zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    继承
    对象与类
    反射
    I/O流
    字符串
    Map的entrySet()方法
    接口与内部类
    Git Usage Summary
    HTML(5)
    毕业设计:下载
  • 原文地址:https://www.cnblogs.com/php-linux/p/13097477.html
Copyright © 2011-2022 走看看