[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 ...
随机推荐
- EventBus学习笔记(一)
EventBus是Android和Java的发布/订阅事件总线 EventBus分三个步骤 1.定义事件 public static class MessageEvent { /* Additiona ...
- 怎么过滤
replace(str, " ", ""); 就是这么简单
- Servlet 监听器Listner
定义: 专门用于对其他对象身上发生的事件或状态改变进行监听和相应处理的对象,当被监视的对象发生情况时,立即采取相应的行动. Servlet 规范为每种事件监听器都定义了相应的接口,它用于监听 ...
- react-quill 富文本编辑器 ---- 图片处理
import React,{Component} from 'react'; import ReactQuill,{ Quill } from 'react-quill'; import 'react ...
- Burp Suite Pro 教程
1.Burp Suite Pro2.0.11破解版-2018.11.06更新 说明基地址 来源:http://ximcx.cn/post-110.html 启动;如果是用的burp2.0,把下面的代码 ...
- 1.8 Double-Opening and Virtual Machine
Since plug-in will be replaced by RN as following years, what is the future of plug-in? the answer i ...
- [Swift]LeetCode37. 解数独 | Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy ...
- [Swift]LeetCode440. 字典序的第K小数字 | K-th Smallest in Lexicographical Order
Given integers n and k, find the lexicographically k-th smallest integer in the range from 1 to n. N ...
- [Swift]LeetCode701. 二叉搜索树中的插入操作 | Insert into a Binary Search Tree
Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert t ...
- [Swift]LeetCode1002. 查找常用字符 | Find Common Characters
Given an array A of strings made only from lowercase letters, return a list of all characters that s ...