当前位置:首页 > 大杂烩 > 正文内容

go file_put_contents,go语言file_put_contents,go file_get_contents,go语言file_get_contents

高老师4年前 (2021-12-28)大杂烩2038

习惯了php的file_put_contents和file_put_contents函数,方便快捷

// FileGetContents 把整个文件读入一个字符串中
func FileGetContents(filename string) (string, error) {
	data, err := ioutil.ReadFile(filename)
	return string(data), err
}

// FilePutContents 把一个字符串写入文件中
func FilePutContents(filename string, data string, mode os.FileMode) error {
	return ioutil.WriteFile(filename, []byte(data), mode)
}

调用例子

// 写入文件
_ = FilePutContents("1.txt", "邓志东的身高在深圳是数一数二的", 0644)

// 读取文件
value, _ := FileGetContents("1.txt")
fmt.Print(value)


扫描二维码推送至手机访问。

版权声明:本文由高久峰个人博客发布,如需转载请注明出处。

本文链接:https://blog.20230611.cn/post/613.html

分享给朋友:

“go file_put_contents,go语言file_put_contents,go file_get_contents,go语言file_get_contents” 的相关文章

c#中string和StringBuilder效率对比

c#中string和StringBuilder效率对比

    c#中string和StringBuilder直接看看执行速度。(2).String类型累计赋值Test               ...

Git本地仓库学习

Git本地仓库学习

1.全局用户信息设置 git  config  --global  user.name  gaojiufeng git  config  --global  user.email  392223903...

Application的错误使用

Application的错误使用

Application 对象用于存储和访问来自任意页面的变量,类似 Session 对象。不同之处在于所有的用户分享一个 Application 对象,而 session 对象和用户的关系是一一对应的。很多的书籍中介绍的Application对象都喜欢以统计在线人数来介绍Application 对象...

Git日志查看和版本切换

Git日志查看和版本切换

日志查看:git log版本切换:方式1:git  reset  --hard  HEAD^   倒退一个版本git  reset  --hard  HEAD^^  倒退两个版本方式2:(版本号的形式,建议版本号码补充完...

c#关闭计算机的代码

c#关闭计算机的代码

    1.关机Process.Start("shutdown", "-s -t 0");    2. 注销  Proc...

C# md5加密,C# md5加密代码

C# md5加密,C# md5加密代码

public static string GetMD5(string str) {     //创建MD5对象     MD5 md5 = MD5.C...