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
+13.2k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+7k Golang : Takes a plural word and makes it singular
+8k Golang : What fmt.Println() can do and println() cannot do
+18.7k Golang : Implement getters and setters
+4.8k Which content-type(MIME type) to use for JSON data
+14.6k Golang : Send email with attachment(RFC2822) using Gmail API example
+29.5k Golang : How to create new XML file ?
+38.1k Golang : Read a text file and replace certain words
+10.3k Golang : Embed secret text string into binary(executable) file
+10.2k Golang : How to profile or log time spend on execution?
+7.9k Setting $GOPATH environment variable for Unix/Linux and Windows
+7.7k Golang : Mapping Iban to Dunging alphabets