how to create a folder in android External Storage Directory?

后端 未结 8 1238
耶瑟儿~
耶瑟儿~ 2020-12-01 04:39

I cannot create a folder in android External Storage Directory.

I have added permissing on manifest,



        
8条回答
  •  春和景丽
    2020-12-01 04:50

    If you are trying to create a folder inside your app directory in your storage.

    Step 1 : Add Permission

    
    

    Step 2 : Add the following

    private String createFolder(Context context, String folderName) {
    
        //getting app directory
        final File externalFileDir = context.getExternalFilesDir(null);
    
        //creating new folder instance
        File createdDir = new File(externalFileDir.getAbsoluteFile(),folderName);
    
        if(!createdDir.exists()){
    
        //making new directory if it doesn't exist already
            createdDir.mkdir();
    
        }
        return finalDir.getAbsolutePath() + "/" +  System.currentTimeMillis() + ".txt";
    }
    

提交回复
热议问题