0

I need to make a directory if not exist. I've wrote codes below

    File backupDir = new File("//test");

    // if (!backupDir.exists())
    backupDir.mkdirs();

I've previously used it without any problem, But now not works and I have no errors! What is the problem? Have you any idea to solve this?

Thanks in advance

Mousa Jafari
  • 677
  • 1
  • 6
  • 21

1 Answers1

1

Have you any idea to solve this?

Use a valid path that you can write to. Not only is //test a strange way to encode a path, you cannot write to it on any Android device from Java code this way. Use appropriate methods, like getFilesDir() or getExternalFilesDir(), to find places that you can write to.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks, Do you know how can I get the root directory of internal storage? – Mousa Jafari Oct 25 '14 at 23:15
  • 1
    @MousaJafari: If you really mean [internal storage](http://commonsware.com/blog/2014/04/07/storage-situation-internal-storage.html), you cannot write to the root of internal storage. – CommonsWare Oct 25 '14 at 23:17
  • Yes I know, I'm sorry my point was not root directory. I want to make a folder near the folders such as Data, System (Root directory) – Mousa Jafari Oct 25 '14 at 23:20
  • @MousaJafari: You do not have write access there. Apps running on rooted devices should have some ability to write there, but I do not know the details. – CommonsWare Oct 25 '14 at 23:22