Not creating folder due to a missing /?

Viewed 154

SNIPPET 1

 public class MyLogs {
          private static File root;

          private static String rootPath;

          static {
            rootPath = Environment.getExternalStorageDirectory().toString() + "/MyFolder/Sub1/Sub2";
            root = new File(rootPath);
            root.mkdirs();
          }
        }

Using the code mentioned above I'm unable to create folder on sdcard. root.mkdirs() return false in this case, however when i use rootPath = Environment.getExternalStorageDirectory().toString() + "/MyFolder/Sub1/Sub2/";(I've added a '/' after Sub2), it creates the folder. I've searched about it but didn't get an answer to it.

SNIPPET 2

String root = Environment.getExternalStorageDirectory().toString();
File myImageFolder = new File(root + "/MyFolder");
myImageFolder.mkdirs();

In this case 'MyFolder' should act as a File but it allows me to create the folder in this case. Kindly enlighten me on this. Thanks in advance.

2 Answers
Related