Skip to content

Commit 722ad1b

Browse files
committed
feat : create , write something and define permission
1 parent 0889d43 commit 722ad1b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Linux/Permissions/main.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func main() {
9+
// Declare variable of type os.File and Create file test.txt
10+
file, err := os.Create("test.txt")
11+
//handle checking error
12+
if err != nil {
13+
//display if having error
14+
fmt.Println("Error creating file : ", err)
15+
}
16+
// closing file after use
17+
defer file.Close()
18+
19+
// write to file
20+
_, err = file.WriteString("Testing I can write to this file")
21+
//handle checking error
22+
if err != nil {
23+
fmt.Println("Error writing to file : ", err)
24+
return
25+
}
26+
27+
//define permissions
28+
err = os.Chmod("test.txt", 0644)
29+
//handle checking error
30+
if err != nil {
31+
fmt.Println("Error changing file permissions :", err)
32+
return
33+
}
34+
35+
// When everything is ok
36+
fmt.Println("File created and permissions successfully")
37+
}

0 commit comments

Comments
 (0)