Check if File Exists in Internal and External Storage – Android and Java Example
This example shows how to check if a given file exists on Android device or not. Java code to find if the file present on internal and external storage of the device.
— Check if File Exists in Android Internal Storage
1 2 3 4 5 6 7 |
public boolean fileExists(Context context, String filename) { File file = context.getFileStreamPath(filename); if (file != null && file.exists()) { return true; } return false; } |
— Check if File Exists in Android External Storage
1 2 3 4 5 6 |
public boolean fileExists() { String fileName = "/appname/data.xml"; String filePath = Environment.getExternalStorageDirectory().getPath() + fileName; File file = new File(filePath); return file.exists(); } |