Android导入CSV到SQLite不是第一行

时间:2014-04-20 20:46:18

标签: java android sqlite csv import

我想导入到SQLite数据库表中,CSV文件中的数据,但CSV文件的第一行包含我不想导入的信息。我能怎么做?这是我用来导入文件的方法:

File root = Environment.getExternalStorageDirectory();
 File exportDir = new File(root.getAbsolutePath());
 File csvFile = new File(exportDir, getString(R.string.app_name)+".csv");

 try {
ContentValues cv = new ContentValues();

CSVReader dataRead = new CSVReader(new FileReader(csvFile));
String[] vv = null;
  while((vv = dataRead.readNext())!=null) {
   cv.clear();
   SimpleDateFormat postFormater = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat currFormater  = new SimpleDateFormat("dd-MM-yyyy");
      String eDDte;
try
`{
Date nDate = currFormater.parse(vv[0]);
            eDDte = postFormater.format(nDate);
            cv.put(EntrateUsciteTable.DATA,eDDte);
        }
         catch (Exception e) {
        }

SQLiteDatabase db = mHelper.getWritableDatabase();
 db.insert(EntrateUsciteTable.TABLE_NAME,null,cv);
}
dataRead.close();
} catch (Exception e) {
Log.e("TAG",e.toString());
}

1 个答案:

答案 0 :(得分:0)

例如使用计数器:

int counter = 0;
while((vv = dataRead.readNext())!=null) {
    if(counter == 0) {
        continue;
        counter++;
    } else {
       // Do the insert
    }
}