goland读取文件写入文件


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)
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM