Check if a File Exists

How to Check if a File Exists

exists() was added in API Level 1
exists() - Returns a boolean indicating whether this file can be found on the underlying file system.

1. Create a Reference to the File named myFile.

2. In the MainActivity.java file, add the below code to your onCreate method.
  1. 
    if (myFile.exists()) {
        //File exists.
    } else {
        //File does not exist. 
    }
    
  2. 3. Alternately, you can test for it to NOT to exist. 

  3. if (!myFile.exists()) {
  4.     //File does not exist.
    } else {
        //File exists. 
    }
  5. 3. Compile and test!

  1. Resources:
    http://developer.android.com/reference/java/io/File.html#exists()
    http://mobile-development-tutorial.blogspot.com/2012/12/android-external-sqlite-database.html
    http://stackoverflow.com/questions/8007993/in-android-check-if-sqlite-database-exists-fails-from-time-to-time