How to check if newly created folder is present into SD Card in Android

十年热恋 提交于 2019-11-27 15:06:36

问题


From my application, I want to store some images into my SD card. For that I need to create a one folder.

At the first time folder will create but after it checks whether that folder is present or not. How can I do it?


回答1:


below code will create a directory if it does not exist

   File direct = new File(Environment.getExternalStorageDirectory() + "/New Folder");

   if(!direct.exists())
    {
        if(direct.mkdir()) 
          {
           //directory is created;
          }

    }



回答2:


You should request the following permission first in your Android manifest :

android.permission.WRITE_EXTERNAL_STORAGE

and execute above code by Rasel for it to work.



来源:https://stackoverflow.com/questions/6911041/how-to-check-if-newly-created-folder-is-present-into-sd-card-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!