Hi, I am developing an application that, as the first thing, puts all lines from a txt-file to a sqlite database. There is about 100.000 words that should be added to the database, and this takes almost an hour to do. Is there a better way to do this, fx. to have a database in the res/ raw resources if it is possible. This is my currently way to do it:
public void getWords(final Context context, final InputStream aFile) { try { InputStreamReader reader = new InputStreamReader(aFile, Charset.forName("UTF-8")); BufferedReader input = new BufferedReader(reader); try { DB = context.openOrCreateDatabase(DATABASE_NAME, 1, null); DB.execSQL("DELETE FROM english"); String line = input.readLine(); int i = 0; while (( line = input.readLine()) != null){ try { DB.execSQL("INSERT OR IGNORE INTO english(word) VALUES ('" + line + "')"); } catch (Exception e) { Log.e("kaloer", e.getMessage()); } if(i % 100 == 0) { Log.d("progress", Integer.toString(i)); try { Thread.sleep(100); } catch(InterruptedException e) { } } i++; } } catch (IOException e) { e.printStackTrace(); } finally { try { input.close(); } catch (IOException e) { e.printStackTrace(); } DB.close(); } } return; } Thank you very much, //Kaloer --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---