Android file-creation fails.
        Posted  
        
            by Alxandr
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Alxandr
        
        
        
        Published on 2010-04-28T22:35:05Z
        Indexed on 
            2010/04/28
            22:37 UTC
        
        
        Read the original article
        Hit count: 357
        
I use the following code to create a folder "mymir" and a file ".nomedia" (in the mymir-folder) on the sdcard of an android unit. However, somehow it fails with the exception that the folder the ".nomedia"-file is to be placed in dosn't exist. Here's the code:
private String EnsureRootDir() throws IOException
{
    File sdcard = Environment.getExternalStorageDirectory();
    File mymirFolder = new File(sdcard.getAbsolutePath() + "/mymir/");
    if(!mymirFolder.exists())
    {
        File noMedia = new File(mymirFolder.getAbsolutePath() + "/.nomedia");
        noMedia.mkdirs();
        noMedia.createNewFile();
    }
    return mymirFolder.getAbsolutePath();
}
© Stack Overflow or respective owner