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 (|).Now that you've been acquainted with CSV files, your task is to create a Go program that appends the comma-separated values contained within the data variable into the songs.csv file.
Below you can see the current contents of the songs.csv file:
Title,Artist,Album,Duration
"Fix You","Coldplay","X&Y",4:56
"Clocks","Coldplay","A Rush of Blood to the Head",5:08
"Yellow","Coldplay","Parachutes",4:27
"Summertime Sadness","Lana Del Rey","Born to Die",4:25
"Young and Beautiful","Lana Del Rey","Born to Die",3:56
"Pumped Up Kicks","Foster the People","Torches",3:59
To do this, you need to use the os.OpenFile() function first to open songs.csv with the os.O_APPEND, os.O_WRONLY flags and with permission mode 0644.
Then you can use the fmt.Fprintln() function to append the comma-separated values of songs contained within the data variable to the songs.csv file.