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.1k Golang : Handle or parse date string with Z suffix(RFC3339) example
+7.2k Golang : Dealing with postal or zip code example
+5.2k Golang : Experimental Jawi programming language
+14.4k Android Studio : Use image as AlertDialog title with custom layout example
+31.9k Golang : Convert an image file to []byte
+6.6k Golang : How to determine if request or crawl is from Google robots
+8.8k Golang : Accept any number of function arguments with three dots(...)
+7.1k Golang : Squaring elements in array
+14k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+43.2k Golang : Convert []byte to image
+7.7k Gogland : Where to put source code files in package directory for rookie