I am downloading a csv from server.And i have to insert its data into sqlite database table (a single table ).I got the file file from server and save it on sdcard . Here is my code of reading Csv file
public synchronized void insertAllDataToDB(String path) {
FileReader file = null;
try {
file = new FileReader(path);
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader buffer = new BufferedReader(file);
String line = "";
sqLite.beginTransaction();
try {
while((line = buffer.readLine()) != null) {
String[] str = line.split(",");
ContentValues values=new ContentValues(4);
if(str.length!=8){
continue;
}
values.put(col1,str[0]);
values.put(col2,str[1]);
values.put(col3,str[2]);
values.put(col4,str[3]);
values.put(col5,str[4]);
values.put(col6,str[5]);
values.put(col7,str[6]);
sqLite.insert(TABLE_NAME,null, values);
Log.e("Inserted",values.toString());
}
} catch (SQLException | IOException e) {
e.printStackTrace();
Log.e("Exception",e.getLocalizedMessage());
}
finally{
}
sqLite.setTransactionSuccessful();
sqLite.endTransaction();
}
It work perfectly but the problem is my Csv file data has comma as itself in its column data and when i am splitting it from comma it also split the data .. Can anyone tell me how to get rid of that problem .Or anyone have another way to achieve this . thanks in advance .. i am stuck