mkdir() works while inside internal flash storage, but not SD card?

前端 未结 4 619
慢半拍i
慢半拍i 2020-11-29 04:33

I am currently building a file management app that allows the user to browse the file system of their device. The user starts off in the root directory / of the

4条回答
  •  长情又很酷
    2020-11-29 04:55

    Try with this. It works fine for me.

    final String NEW_FOLDER_NAME = "TestFolder";
    
    String extStore = System.getenv("EXTERNAL_STORAGE");
    File f_exts = new File(extStore, NEW_FOLDER_NAME);
    
    String secStore = System.getenv("SECONDARY_STORAGE");
    File f_secs = new File(secStore, NEW_FOLDER_NAME);
    
    testPath(f_exts);
    
    textPath(f_secs);
    

    and change boolean value in testPath function as follows

    boolean success;
    if(path.exists()) {
        // already created
        success = true;
    } else {
        success = path.mkdir();
    }
    

    If folder already exists, path.mkdir() method return false.

    and done.!!!

    reference from this question.

提交回复
热议问题