[Go] 写文件和判断文件是否存在
发布时间:2021-05-21 06:46:48 所属栏目:大数据 来源: https://www.jb51.cc
导读:OpenFile得到一个File,然后调用它的Write,参数是字节切片 Stat看看返回错误没有 package mainimport ( " fmt " os " )func main() { file := 1.txt f,_ : = os.OpenFile( file ,os.O_RDWR|os.O_CREATE, 0766 ) f.Write([] byte ( 你好 )) f.Close() // 判
OpenFile得到一个File,然后调用它的Write,参数是字节切片 package main import ( "fmt" os" ) func main() { file := 1.txt f,_ := os.OpenFile(file,os.O_RDWR|os.O_CREATE,0766) f.Write([]byte(你好)) f.Close() //判断文件是否存在 _,err := os.Stat(file) if err != nil && os.IsNotExist(err) { 存在 fmt.Println(不存在) } else { 存在) } } ? (编辑:北几岛) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |