If you need to discover basic information about the accessed file, Go's standard library provides a way on how you can do this. This recipe shows how you can access this information.
Getting file information
How to do it...
- Open the console and create the folder chapter06/recipe01.
- Navigate to the directory.
- Create the sample test.file with the content This is test file.
- Create the fileinfo.go file with the following content:
package main
import (
"fmt"
"os"
)
func main() {
f, err := os.Open("test.file")
if err != nil {
panic(err)
}
fi, err := f.Stat()
if err != nil {
panic...