#golang #go #ioutil #file
WriteFile with permissions using ioutil package
--------------------------------------------------------------------------
filedemo.go
------------------
package main
import(
"io/ioutil"
)
func main(){
data := []byte("Welcome")
err := ioutil.WriteFile("/home/ambasoft/Desktop/sample.txt",data,0700)
//0100 - Execute only
//0200 - Write only
//0300 - Write and Execute
//0400 - Read only
//0500 - Read and Execute
//0600 - Read and Write
//0700 - Read, Write and Execute
if(err != nil) {
panic(err)
}
}
Temporary Directory
--------------------------------
tempdemo.go
----------------------
package main
import (
"io/ioutil"
"os"
)
func main(){
dir,err := ioutil.TempDir("/home/ambasoft/Desktop","mytemp")
if(err != nil){
panic(err)
}
defer os.RemoveAll(dir) //Remove directories manually
}
Temporary File
-------------------------
tempfiledemo.go
---------------------------
package main
import (
"io/ioutil"
"os"
)
func main(){
f,err := ioutil.TempFile("/home/ambasoft/Desktop","mytemp")
if(err != nil){
panic(err)
}
defer os.Remove(f.Name()) //Remove file manually
}
Смотрите видео Go (golang) Advanced Tutorials - File I/O using ioutil package , Temporary File, Temporary Directory онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал Ambasoft Java 18 Февраль 2021. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 1,089 раз и оно понравилось 19 посетителям.