1 Star 1 Fork 1

xiaoyutab / xgotool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
write.go 609 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiaoyutab 提交于 2024-02-29 17:02 . 调整写入文件的权限授权
package xfile
import (
"errors"
"os"
)
// 写入文件
//
// file_path 文件路径
// cont 文件内容
func Write(file_path string, cont []byte) error {
if file_path == "" {
return errors.New("文件名不能为空")
}
file, err := os.OpenFile(file_path, os.O_CREATE|os.O_RDWR, 0666)
if err != nil {
return err
}
defer file.Close()
// 写入文件
_, err = file.Write(cont)
if err != nil {
return err
}
return nil
}
// 写入文件(字符串)
//
// file_path 文件路径
// cont 文件内容
func WriteString(file_path, cont string) error {
return Write(file_path, []byte(cont))
}
Go
1
https://gitee.com/xiaoyutab/xgotool.git
git@gitee.com:xiaoyutab/xgotool.git
xiaoyutab
xgotool
xgotool
v0.3.11

搜索帮助

53164aa7 5694891 3bd8fe86 5694891