Another common file format apart from .txt files are the .csv files — CSV stands for Comma Separated Values.
A CSV file stores values that are separated by a specific delimiter, commonly a comma
A CSV file stores values that are separated by a specific delimiter, commonly a comma
(,). However, there are other common delimiters like the semicolon (;), a tab (\t), blank spaces (" ") and even the pipe character (|).Below you can see the contents of a sample CSV file:
Title,Artist,Album,Duration
"Anti-Hero","Taylor Swift","Midnights",3:21
"Midnight Rain","Taylor Swift","Midnights",2:54
Now that you've been acquainted with CSV files, your task is to create a Go program that writes the comma-separated values contained within the data variable into the songs.csv file.
To do this, you can use the os.WriteFile() function to write the data directly into songs.csv, or you can use the os.Create() function to create songs.csv first and then use fmt.Fprintln() to write the data into the file.