How to create a sub directory inside a private directory in android

I have created a directory like this:

File mydir = context.getDir("my_private_dir", Context.MODE_PRIVATE);

Now I want to create another directory inside my_private_dirfor which I've tried doing it this way:

 File file = new File(mydir.getAbsolutePath()+ File.separator + date);
            if (file.mkdir())
                Log.d(context.getClass().getSimpleName()," date dir created");

I don't know why this is not working out. The subdirectory is not getting created at all.

I want all the directories to be private and only my app should be able to access it. SO I thought to make the parent directory private and to create subdirectories inside it normally will be enough. But I'm not able to understand why the subdirectory is not getting created.

Can anyone please help me with this problem?

Thanks in advance :)

Regards

1 answer

  • answered 2017-06-17 18:54 Meikiem

    Try to use mkdirs() instead of mkdir()

     File file = new File(mydir.getAbsolutePath()+ File.separator + date);
            if (file.mkdirs())
                Log.d(context.getClass().getSimpleName()," date dir created");