0

I have a populated database that should be copied if database not exist(Often occurred when application is installed). I have problem in checking database existence.

if (!new File(context.getDatabasePath(DATABASE_NAME), DATABASE_NAME).isFile()) {

    // database not exist
}

or

if (!new File(context.getDatabasePath(DATABASE_NAME), DATABASE_NAME).exists()) {

    // database not exist
}

In the both of upper cases, result is true while database does not exist!

IAmGroot
  • 13,760
  • 18
  • 84
  • 154
Mousa Jafari
  • 677
  • 1
  • 6
  • 21
  • 1
    the second method is the way to do it, are you sure the file does not exist, and that you are not just looking in the wrong folder for it. See http://stackoverflow.com/a/16238204/940834 for more – IAmGroot Nov 26 '14 at 16:57
  • 1
    "I have a populated database" -- please consider [using `SQLiteAssetHelper`](https://github.com/jgilfelt/android-sqlite-asset-helper) for this, rather than rolling your own implementation. – CommonsWare Nov 26 '14 at 17:00

0 Answers0