如何在 android 中的私有目录中创建子目录

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

我创建了一个这样的目录:

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

现在我想在 my_private_dir 中创建另一个目录,为此我尝试这样做:

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

我不知道为什么这行不通。根本没有创建子目录。

我希望所有目录都是私有的,只有我的应用程序可以访问它。所以我认为将父目录设为私有并在其中创建子目录通常就足够了。但是我不明白为什么没有创建子目录。

谁能帮我解决这个问题?

提前致谢:)

此致

尝试使用 mkdirs() 而不是 mkdir()

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