Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/csv"
- "fmt"
- "io"
- "log"
- "os"
- )
- func main() {
- // open file
- f, err := os.Open("data.csv")
- if err != nil {
- log.Fatal(err)
- }
- // remember to close the file at the end of the program
- defer f.Close()
- // read csv values using csv.Reader
- csvReader := csv.NewReader(f)
- for {
- rec, err := csvReader.Read()
- if err == io.EOF {
- break
- }
- if err != nil {
- log.Fatal(err)
- }
- // do something with read line
- fmt.Printf("%+v\n", rec)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement