how to create a folder in android External Storage Directory?

后端 未结 8 1254
耶瑟儿~
耶瑟儿~ 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 05:10

    we can Create Folder or Directory on External storage as :

     String myfolder=Environment.getExternalStorageDirectory()+"/"+fname;
         File f=new File(myfolder);
         if(!f.exists())
         if(!f.mkdir()){
         Toast.makeText(this, myfolder+" can't be created.", Toast.LENGTH_SHORT).show();
    
        }
        else
         Toast.makeText(this, myfolder+" can be created.", Toast.LENGTH_SHORT).show();
    }
    

    and if we want to create Directory or folder on Internal Memory then we will do :

    File folder = getFilesDir(); 
    File f= new File(folder, "doc_download"); 
    f.mkdir();
    

    But make Sure you have given Write External Storage Permission. And Remember that if you have no external drive then it choose by default to internal parent directory. I'm Sure it will work .....enjoy code

提交回复
热议问题