find the size of a csv file in go

To find the size of a CSV file in Go, you can use the Stat function from the os package to get the FileInfo of the file. Then, you can access the Size() method of the FileInfo to get the size of the file in bytes.

Here's an example code snippet:

main.go
package main

import (
    "fmt"
    "os"
)

func main() {
    // open the file
    file, err := os.Open("file.csv")
    if err != nil {
        panic(err)
    }
    defer file.Close()

    // get the file info
    fileInfo, err := file.Stat()
    if err != nil {
        panic(err)
    }

    // get the file size in bytes
    fileSize := fileInfo.Size()
    fmt.Printf("The size of file.csv is %d bytes\n", fileSize)
}
421 chars
26 lines

In this example, we open the CSV file file.csv, get its FileInfo, and then print out its size in bytes.

related categories

gistlibby LogSnag