I need help while reading the CSV file
Hello
I am trying to process the CSV file and storing the data into the ArrayList
Some of the columns has got a string which could consist of "comma" character,
So how can I deal for example:
"Curative (acute) care beds, density per 1 000 population",2000,Australia,3.6, so i want to avoid this "," character in the first "Curative (acute) care beds, density per 1 000 population" i want this to insert as one token in arraylist , but my code is taking as two tokens.
Code:
public void readfile(String filename) throws IOException
{
String strData;
int no_lines=0;
BufferedReader bf= new BufferedReader(new FileReader(filename));
String line = null;
String strLine = "";
StringTokenizer st = null;
int tokenNumber = 0;
int count;
while((strLine=bf.readLine())!=null)
{
Element e = new Element();
count = 1;
// System.out.println(strLine);
st = new StringTokenizer(strLine, "\"");
// System.out.println("The data from file " + strLine);
while(st.hasMoreTokens())
{
//display csv values
//tokenNumber++;
strData = st.nextToken();
// System.out.println("The data from file " + strData);
if(count==1){
// System.out.println("The data from file " + strData);
e.settype(strData); // thirrim reference e per ta thirrru metodet setup e cila e merr vetem type series dhe pastaj i fusim me nje arraylist
}
else if(count==2){
e.setyear(strData);
}
else if (count==3){
e.setcountry(strData);
}
else if (count==4){
e.setvalue(strData);
}
else {}
count++;
}
no_lines++;
listofseries.add(e);
}