Code example for File

Methods: canReadcanWriteexistsisDirectorymkdirs

0
    public static boolean ensureDirectoryExistsAndIsReadWritable(File dir) {
        if (dir == null) {
            return false; 
        } 
 
        if (dir.exists()) {
            if (!dir.isDirectory()) {
                Log.w(TAG, dir + " exists but is not a directory.");
                return false; 
            } 
        } else { 
            if (dir.mkdirs()) {
                Log.i(TAG, "Created directory " + dir);
            } else { 
                Log.w(TAG, "Failed to create directory " + dir);
                return false; 
            } 
        } 
 
        if (!dir.canRead()) {
            Log.w(TAG, "No read permission for directory " + dir);
            return false; 
        } 
 
        if (!dir.canWrite()) {
            Log.w(TAG, "No write permission for directory " + dir);
            return false; 
        } 
        return true; 
    } 
Contextual code suggestions in your IDE  Get Codota for Java