Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/csv: #52225

Closed
Deepanshusuman opened this issue Apr 8, 2022 · 0 comments
Closed

encoding/csv: #52225

Deepanshusuman opened this issue Apr 8, 2022 · 0 comments

Comments

@Deepanshusuman
Copy link

Deepanshusuman commented Apr 8, 2022

go version go1.17.8 windows/amd64

Does this issue reproduce with the latest release: idk

What did you do?

when I fetch the records via this code from CSV from the below code and then write back the records in another file then some of the records are missing.

func getcsvData(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.Error())
	}

	return records
}


func writeback(){
records := getcsvData(file)
	
	sorted, err := os.OpenFile("new.csv", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777)
	if err != nil {
		panic(err.Error())
	}

	sortedwriter := csv.NewWriter(sorted)
	for _, item := range records {
		if err = sortedwriter.Write(item); err != nil {
			panic(err)
		}
	}
	sortedwriter.Flush()
	sorted.Close()
}

What did you expect to see?

all the records

What did you see instead?

when I ran on 109157 records read then it wrote 109144 records

@golang golang locked and limited conversation to collaborators Apr 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants