Search code examples
androidfilesd-cardcreatefilecreate-directory

Created folder is not visible in the file explorer..


I have a problem with creating a folder and a file on the sdcard.

Here's the code:

    File folder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/folder");
    boolean success;
    if (!folder.exists()) {
        success = folder.mkdirs();
    }
    File obdt = new File(folder, "file.txt");
    try {
        success = obdt.createNewFile();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

With this code I expect to create the folderfolder in the Download folder of the sdcard and in this the file file. I want that the user can access the file. So I want to put it in a shared folder.
The success variable is true and when I run the code again the folder already exists and doesnt come in the if-block.
But I can't see the created folder and file on the sdcard in file explorer.

Info:getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() returns storage/sdcard/Download

I work with a Galaxy Nexus.


Solution

  • Damn! :)

    Now I solved my problem...I was misunderstanding the operation of creating files in the file system.
    When I spoke of file explorer I meant the file explorer of the operating system and NOT the file explorer in the DDMS :).
    I thought when I create a file I will see it in the file explorer of the operating system but when the device is connected to the PC the files can only be seen in the DDMS file explorer.
    Sorry I'm new to Android ;)

    When the App is running standalone without PC connection and afterwards I connect with the PC I see the created files and folders of course :)

    Thanks for help