This commit is contained in:
aozhiwei 2020-08-28 23:27:02 +08:00
parent 5d0b0eacad
commit f54243a465

View File

@ -1,24 +1,44 @@
package q5
import "ioutil"
import "io"
import "os"
import "bufio"
type CsvReader struct {
columns map[string]int32
values []XValue
currLine int32
currLine int
lines []string
}
func (this *CsvReader) Load(fileName string) bool {
f, err := ioutil.ReadFile(fileName)
this.columns = map[string]int32{}
this.values = []XValue{}
this.currLine = 0
this.lines = []string{}
f, err := os.Open(fileName)
if err == nil {
defer f.Close()
br := bufio.NewReader(f)
for {
line, _, c := br.ReadLine()
if c == io.EOF {
break
}
this.lines = append(this.lines, string(line))
}
}
return err == nil
}
func (this *CsvReader) NextLine() bool {
if this.currLine >= len(this.lines) {
return false
}
this.currLine++
return true
}