Lesson 55 of 60
GoReading & Writing CSV Files
10 minutes
Course progress92%
CSV Helpers
This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.
import (
"encoding/csv"
"os"
)
func writeCSV(path string, records [][]) {
f, err := os.Create(path)
err != { err }
f.Close()
w := csv.NewWriter(f)
w.Flush()
w.WriteAll(records)
}
([][], ) {
f, err := os.Open(path)
err != { , err }
f.Close()
r := csv.NewReader(f)
r.ReadAll()
}