How to Check if a File Exists
exists() was added in API Level 1exists() - Returns a boolean indicating whether this file can be found on the underlying file system.
1. Create a Reference to the File named myFile.
if (myFile.exists()) { //File exists. } else { //File does not exist. }
- 3. Alternately, you can test for it to NOT to exist.
- if (!myFile.exists()) {
//File does not exist. } else { //File exists. }
3. Compile and test!
Related Articles