how to create a folder in android External Storage Directory?

后端 未结 8 1134
耶瑟儿~
耶瑟儿~ 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

    0 讨论(0)
  • 2020-12-01 05:12

    I can create a folder in android External Storage Directory.

    I have added permissing on manifest,

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    

    Here is my code:

    String folder_main = "Images";
    
    File outerFolder = new File(Environment.getExternalStorageDirectory(), folder_main);
    
    File inerDire = new File(outerFolder.getAbsoluteFile(), System.currentTimeMillis() + ".jpg");
    
    if (!outerFolder.exists()) {
    
        outerFolder.mkdirs();
    
    }
    if (!outerFolder.exists()) {
    
        inerDire.createNewFile();
    
    }
    
    • outerFolder.mkdirs(); // This will create a Folder

    • inerDire.createNewFile(); // This will create File (For E.g .jpg
      file)

    0 讨论(0)
提交回复
热议问题