Home >Backend Development >Golang >How to Determine the Length of a File in Go?
Determining File Length in Go
The question arises: how can you determine the length of a file in Go? While the docs for golang.org/pkg/os/#File may not explicitly mention it, there is a simple method to extract this information.
To obtain the file length in Go, follow these steps:
Here's an example code snippet:
fi, err := f.Stat() if err != nil { // Could not obtain stat, handle error } fmt.Printf("The file is %d bytes long", fi.Size())
This code snippet assumes that f is an *os.File object representing the file whose length you want to determine.
The above is the detailed content of How to Determine the Length of a File in Go?. For more information, please follow other related articles on the PHP Chinese website!