2017-06-17 78 views
0

私人目录内的一个子目录我已经创建了一个目录是这样的:如何创建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"); 

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

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

任何人都可以请帮我解决这个问题吗?

感谢提前:)

问候

+0

“我试着做这种方式” - 使用'新文件(mydir.getAbsolutePath(),日期)'。 “子目录根本没有被创建” - 你究竟是如何确定**的? “我希望所有的目录都是私人的,只有我的应用程序能够访问它 - ”[内部存储]上的所有内容(https://commonsware.com/blog/2014/04/07/storage-situation-internal -storage.html)是私有的,它包含'getDir()'。 – CommonsWare

回答

0

尝试使用mkdirs()代替的mkdir()

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

非常感谢,帮助我创建子目录的人。但你能帮我理解为什么mkdirs()和为什么不mkdir()? –