首页 > 其他 > 详细

goland读取文件写入文件

时间:2019-10-26 11:15:14      阅读:254      评论:0      收藏:0      [点我收藏+]
package main

import (
"fmt"
"io/ioutil"
"strings"
)
/**
* 读取文件
* string name 文件名称
*/
func ReadFile(name string) {
if contents,err := ioutil.ReadFile(name);err == nil {
result := strings.Replace(string(contents),"\n","",1)
fmt.Println("ReadFile:",result)
}
}
/**
* 写入文件
* string name 文件名称
* byte content 文件内容
*/
func WriteFile(name string, content []byte){
if ioutil.WriteFile(name, content, 0644) == nil{
fmt.Println("WriteFile")
}else{
fmt.Println("NOT WriteFile")
}
}

func main() {
name := "content.txt"
content := "content"
WriteFile(name, []byte(content))
ReadFile(name)
}

goland读取文件写入文件

原文:https://www.cnblogs.com/cc-forever/p/11742007.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!