繁体   English   中英

Android将CSV导入SQLite而不是第一行

[英]Android import CSV to SQLite not first row

我想将CSV文件中的数据导入到SQLite数据库表中,但是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());
}

例如,带有一个计数器:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM