Golang Read Csv File

[Solved] Golang Read Csv File | Go - Code Explorer | yomemimo.com
Question : golang read csv file

Answered by : magnificent-mole-0l4b2ruizm3a

package main
import ( "encoding/csv" "fmt" "log" "os"
)
func readCsvFile(filePath string) [][]string { f, err := os.Open(filePath) if err != nil { log.Fatal("Unable to read input file " + filePath, err) } defer f.Close() csvReader := csv.NewReader(f) records, err := csvReader.ReadAll() if err != nil { log.Fatal("Unable to parse file as CSV for " + filePath, err) } return records
}
func main() { records := readCsvFile("../tasks.csv") fmt.Println(records)
}

Source : https://stackoverflow.com/questions/24999079/reading-csv-file-in-go | Last Update : Mon, 25 Jan 21

Question : read csv in Go

Answered by : glamorous-gnat-ntlzpja55ut1

package main
import ( "encoding/csv" "fmt" "log" "os"
)
func readCsvFile(filePath string) [][]string { f, err := os.Open(filePath) if err != nil { log.Fatal("Unable to read input file " + filePath, err) } defer f.Close() csvReader := csv.NewReader(f) records, err := csvReader.ReadAll() if err != nil { log.Fatal("Unable to parse file as CSV for " + filePath, err) } return records
}
func main() { records := readCsvFile("../tasks.csv") fmt.Println(records)
}

Source : https://stackoverflow.com/questions/24999079/reading-csv-file-in-go | Last Update : Wed, 21 Sep 22

Answers related to golang read csv file

Code Explorer Popular Question For Go