Parse large csv files java on Android -


i have csv file, need migrate database. created class parse , transfer database, quite slow. import takes 3 minutes. there way make faster? apologize english. in advance!

final string[] scancodes = {"codeproduct", "scancode"}; dbsync.importcsv(scancodes, "scancodes.csv", "scancodes");    //// ..... ////  public void importcsv(string[] tablecol, string namefile, string nametable) {         final file database_directory = new file(         environment.getexternalstoragedirectory(), "importexport");         final file path = new file(database_directory,"scancodes.csv");         contentvalues cv = new contentvalues();         bufferedreader br = null;         string s = "";         boolean skiplines = true;         string[] data;         db.begintransaction();         try {             br = new bufferedreader(new inputstreamreader(new fileinputstream(path), "windows-1251"));             while ((s = br.readline()) != null) {                 //skip header                    if (skiplines) {                         skiplines = false;                         continue;                     }                 //- 1 not skip blank                 data = s.split(";", -1);                 (int = 0; < data.length - 1; ++i) {                     cv.put(tablecol[i], data[i]);                 }                 db.insert(nametable, null, cv);             }             db.settransactionsuccessful();         } catch (ioexception e) {             e.printstacktrace();         } {             try {                 db.endtransaction();                 br.close();                 new folder().deletefolder();              } catch (ioexception e) {                 e.printstacktrace();             }         }     } 

edit added encoding

there bulkinsert method. should improve performance quite bit.

as far understand reading .csv file locally. instead of reading .csv file can ship apk valid sqlite database in assets folder , can move file databases folder described in below link:

http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -