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

时间:2017-06-17 18:54:03

标签: android android-file

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

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");

我不知道为什么这不起作用。根本没有创建子目录。

我希望所有目录都是私有的,只有我的应用程序才能访问它。所以我想将父目录设为私有,并在其中创建子目录通常就足够了。但是我无法理解为什么子目录没有被创建。

有人可以帮我解决这个问题吗?

提前致谢:)

此致

1 个答案:

答案 0 :(得分:1)

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

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