The go language reads the csv file and outputs the method
- 2020-05-26 09:20:32
- OfStack
This article illustrates how the go language reads the csv file and outputs it. Share with you for your reference. The specific implementation method is as follows:
package main
import (
"encoding/csv"
"fmt"
"io"
"os"
)
func main() {
file, err := os.Open("names.txt")
if err != nil {
fmt.Println("Error:", err)
return
}
defer file.Close()
reader := csv.NewReader(file)
for {
record, err := reader.Read()
if err == io.EOF {
break
} else if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println(record) // record has the type []string
}
}
I hope this article has been helpful to your programming of Go language.