Create Text File
Create new folder named src. In src folder, create new folder named data. In data folder, create new text file named a.txt as below:
Hello World
Application
In src folder, create new file named main.go as below:
package main
import (
"fmt"
"os"
)
func main() {
file, err := os.Stat("data/a.txt")
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Name: ", file.Name())
fmt.Println("Size(bytes): ", file.Size())
fmt.Println("Permission: ", file.Mode())
fmt.Printf("Perm: %04o", file.Mode().Perm())
}
}
Output
Open Terminal windows in Visual Studio Code and run command line: go run main.go
Name: a.txt
Size(bytes): 11
Permission: -rw-rw-rw-
Perm: 0666