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创建目录写文件判断文件的更多相关文章

  1. NSIS:使用FileFunc.nsh头文件判断文件版本

    原文 NSIS:使用FileFunc.nsh头文件判断文件版本 这里,轻狂拿WMP10做一个例子.关于WMP10的原始安装文件,可以下载后通过/C /T:D:\Windows Media Player ...

  2. 判断文件是否存在,不存在创建文件&&判断文件夹是否存在,不存在创建文件夹

    1.判断文件是否存在,不存在创建文件 File file=new File("C:\\Users\\QPING\\Desktop\\JavaScript\\2.htm"); if( ...

  3. C#取得控制台应用程序的根目录方法 判断文件夹是否存在,不存在就创建

    取得控制台应用程序的根目录方法1:Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径2:AppDomain.CurrentDomain.BaseDirect ...

  4. C#取得程序的根目录以及判断文件是否存在

    一:获取根目录的方法 取得控制台应用程序的根目录方法方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径方法2.AppDomain.CurrentDo ...

  5. C#判断文件及文件夹是否存在并创建(C#判断文件夹存在)

    protected void Button1_Click(object sender, EventArgs e) { if (Directory.Exists(Server.MapPath(" ...

  6. Asp.Net判断文件是否存在

    在上传文件时经常要判断文件夹是否存在,如果存在就上传文件,否则新建文件夹再上传文件 判断语句为 if (System.IO.Directory.Exists(Server.MapPath(" ...

  7. C#判断文件和文件夹是否存在 不存在则创建

    using System.IO;string path = @"D:\accountDaoRu\";        if (Directory.Exists(path) == fa ...

  8. asp.net判断文件或文件夹是否存在

    在上传文件时经常要判断文件夹是否存在,如果存在就上传文件,否则新建文件夹再上传文件 判断语句为 if (System.IO.Directory.Exists(Server.MapPath(" ...

  9. C# 判断文件和文件夹是否存在并创建

    C# 判断文件和文件夹是否存在并创建 using System; using System.Data; using System.Configuration; using System.Collect ...

随机推荐

  1. CDN(Content Delivery Network)技术原理概要

    简介 CDN(Content Delivery Network)即内容分发网络,依靠部署在各地的边缘服务器,通过中心平台的负载均衡.内容分发.调度等功能,使用户就近获取所需内容,提高用户访问响应速度和 ...

  2. vue变异方法

    push()  往数组最后面添加一个元素,成功返回当前数组的长度    pop()  删除数组的最后一个元素,成功返回删除元素的值    shift()  删除数组的第一个元素,成功返回删除元素的值u ...

  3. 完整的系统帮助类Utils

    //来源:http://www.cnblogs.com/yuangang/p/5477324.html using System; using System.Collections.Generic; ...

  4. unity网络----简单基础

    网络 TCP:与打电话类似,通知服务到位 UDP:与发短信类似,消息发出即可 IP和端口号是网络两大重要成员 端口号(Port)分为知名端口号[0-1024,不开放)和动态端口号[1024,10000 ...

  5. [译]async/await中阻塞死锁

    这篇博文主要是讲解在async/await中使用阻塞式代码导致死锁的问题,以及如何避免出现这种死锁.内容主要是从作者Stephen Cleary的两篇博文中翻译过来. 原文1:Don'tBlock o ...

  6. nginx+letsencrypt搭建https站点

    1. 申请好自己的域名 dockerhub.xxx.com,并解析好IP. 2. 安装nginx(默认开通了http) ,修改 server_name dockerhub.xxxx.com; 启动. ...

  7. 【RL-TCPnet网络教程】第31章 Telnet远程登录基础知识

    第31章      Telnet远程登录基础知识 本章节为大家讲解Telnet (Teletype Network) 的基础知识,方便后面章节的实战操作. (本章的知识点主要整理自网络) 31.1   ...

  8. [Swift]LeetCode61. 旋转链表 | Rotate List

    Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: I ...

  9. [SQL]LeetCode178. 分数排名 | Rank Scores

    Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...

  10. [Swift]LeetCode778. 水位上升的泳池中游泳 | Swim in Rising Water

    On an N x N grid, each square grid[i][j]represents the elevation at that point (i,j). Now rain start ...