Golang encoding/csv.Writer.Flush() function example
package encoding/csv
Flush writes any buffered data to the underlying io.Writer. To check if an error occurred during the Flush, call Error.
Golang encoding/csv.Writer.Flush() function usage example
package main
import (
"encoding/csv"
"fmt"
"os"
)
func main() {
csvfile, err := os.Create("output.csv")
if err != nil {
fmt.Println("Error:", err)
return
}
defer csvfile.Close()
records := [][]string{{"item1", "value1"}, {"item2", "value2"}, {"item3", "value3"}}
writer := csv.NewWriter(csvfile)
for _, record := range records {
err := writer.Write(record)
if err != nil {
fmt.Println("Error:", err)
return
}
}
writer.Flush() // <---- here
}
Reference :
Advertisement
Something interesting
Tutorials
+11.6k Golang : Simple file scaning and remove virus example
+14k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+10.1k Golang : Edge detection with Sobel method
+23.6k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+18.4k Golang : Read binary file into memory
+14.2k Golang : Convert IP version 6 address to integer or decimal number
+4.6k Linux : sudo yum updates not working
+6.3k Golang : Test input string for unicode example
+40.5k Golang : Convert to io.ReadSeeker type
+10.3k Golang : Detect number of faces or vehicles in a photo
+18k Golang : Check if a directory exist or not
+11.1k Golang : Fix go.exe is not compatible with the version of Windows you're running