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
+5.6k Golang : Return multiple values from function
+9.1k Golang : Executing and evaluating nested loop in html template
+17.4k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+20.3k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+7.8k SSL : How to check if current certificate is sha1 or sha2 from command line
+7.7k Golang : Gorrila set route name and get the current route name
+6.7k Golang : How to search a list of records or data structures
+14.1k Golang : convert(cast) string to float value
+16.2k Golang : Update database with GORM example
+13.7k Golang : Generate Code128 barcode
+7.8k Golang : How to stop user from directly running an executable file?
+27.7k Golang : Convert CSV data to JSON format and save to file