[Go] golang创建目录写文件判断文件
package main import (
"log"
"os"
) func main() {
//创建目录
os.Mkdir("test", os.ModePerm) //写文件
file := "1.txt"
file6, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE, 0766)
if err != nil {
log.Printf("error")
}
data := "陶士涵"
file6.WriteString(data) //以字符串写入
file6.Write([]byte(data)) //以字节切片写入
file6.Close() //判断文件
bool, err := isFileExist(file)
if bool {
log.Println("存在")
}
} //判断文件文件夹是否存在
func isFileExist(path string) (bool, error) {
fileInfo, err := os.Stat(path) if os.IsNotExist(err) {
return false, nil
}
//我这里判断了如果是0也算不存在
if fileInfo.Size() == 0 {
return false, nil
}
if err == nil {
return true, nil
}
return false, err
}
[Go] golang创建目录写文件判断文件的更多相关文章
- NSIS:使用FileFunc.nsh头文件判断文件版本
原文 NSIS:使用FileFunc.nsh头文件判断文件版本 这里,轻狂拿WMP10做一个例子.关于WMP10的原始安装文件,可以下载后通过/C /T:D:\Windows Media Player ...
- 判断文件是否存在,不存在创建文件&&判断文件夹是否存在,不存在创建文件夹
1.判断文件是否存在,不存在创建文件 File file=new File("C:\\Users\\QPING\\Desktop\\JavaScript\\2.htm"); if( ...
- C#取得控制台应用程序的根目录方法 判断文件夹是否存在,不存在就创建
取得控制台应用程序的根目录方法1:Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径2:AppDomain.CurrentDomain.BaseDirect ...
- C#取得程序的根目录以及判断文件是否存在
一:获取根目录的方法 取得控制台应用程序的根目录方法方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径方法2.AppDomain.CurrentDo ...
- C#判断文件及文件夹是否存在并创建(C#判断文件夹存在)
protected void Button1_Click(object sender, EventArgs e) { if (Directory.Exists(Server.MapPath(" ...
- Asp.Net判断文件是否存在
在上传文件时经常要判断文件夹是否存在,如果存在就上传文件,否则新建文件夹再上传文件 判断语句为 if (System.IO.Directory.Exists(Server.MapPath(" ...
- C#判断文件和文件夹是否存在 不存在则创建
using System.IO;string path = @"D:\accountDaoRu\"; if (Directory.Exists(path) == fa ...
- asp.net判断文件或文件夹是否存在
在上传文件时经常要判断文件夹是否存在,如果存在就上传文件,否则新建文件夹再上传文件 判断语句为 if (System.IO.Directory.Exists(Server.MapPath(" ...
- C# 判断文件和文件夹是否存在并创建
C# 判断文件和文件夹是否存在并创建 using System; using System.Data; using System.Configuration; using System.Collect ...
随机推荐
- 反沙箱——SetErrorMode
目录 1.前言 2.原理讲解 3.代码实现 4.参考 1.前言 利用SetErrorMode进行反沙箱的技术,在2010年就有被提出,但是之前搜了很久都没有相关内容,这里简单的说一下这个反沙箱的实现. ...
- 18 ArcGIS API for JavaScript4.X 系列加载天地图(经纬度)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 浏览器css隐藏滚动条的方法!除了IE一般都支持
::-webkit-scrollbar { /* 滚动条整体部分 */ width:0px; margin-right:2px}::-webkit-scrollbar-track-piece { /* ...
- node.js Setup Wizard ended prematurely 安装失败
解决: 1. 按照管理员权限运行. 2.安装时禁用掉node 运行环境中的performance counters 和 ETW,或者可以尝试先禁用performance counters .
- Python-常用字符串操作
name = 'shanbaoliang.exe' print(name.capitalize()) #将字符串首字母大写 print(name.center(50,'-')) #把字符串居中,并用特 ...
- Javascript高级编程学习笔记(87)—— Canvas(4)绘制路径
绘制路径 2D上下文支持许多在画布上绘制路径的方法 通过路径可以创造出复杂的形状和线条,要绘制路径首先必须调用beginPath()方法,表示开始绘制路径 然后再通过下列的方法绘制路径: arc(x, ...
- [Swift]LeetCode146. LRU缓存机制 | LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- [Swift]LeetCode622. 设计循环队列 | Design Circular Queue
Design your implementation of the circular queue. The circular queue is a linear data structure in w ...
- Eclipse工具:常用快捷键记录
Eclipse快捷键: 按键操作 按键作用 输入sysout再按下Ctrl+Space System.out.println() Ctrl+1 当某行出错时时,跳出帮 ...
- C# - 2017微软校园招聘笔试题 之 MS Recognition[待解决]
MS Recognition 在线提交: hihoCoder 1402 http://hihocoder.com/problemset/problem/1402 类似: OpenJudge - I:P ...