public static boolean checkIfFileExists(String path) { File f = new File(Environment.getExternalStorageDirectory() + path); boolean ret = false; if (f.exists() && f.isFile()) { ret = true; } Debug.i("Checking for file: " + path + " ret = " + ret); return ret; }
public static boolean checkForDirectory(Context context, String path) { File f = new File(Environment.getExternalStorageDirectory().getPath()); f = new File(f, path); if (f.exists() == true && f.isDirectory() == true) { Debug.e(path + " already exists."); return true; } Debug.e(path + " doesnt exists. So trying to create"); f.mkdirs(); f.setExecutable(true); f.setReadable(true); f.setWritable(true); // initiate media scan and put the new things into the path array to // make the scanner aware of the location and the files you want to see MediaScannerConnection.scanFile(context, new String[] {f.toString()}, null, null); Boolean successs = (f.exists() && f.isDirectory()); Debug.i("checking if it was successfully created. " + successs); return successs; }