Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why app_ appears while creating directory using ContextWraper.getDir

Tags:

java

file

android

In my app, I used this code:

File DirectoryPath = cw.getDir("custom", Context.MODE_PRIVATE); 

While creating a directory, and it returns:

/data/data/com.custom/app_custom**

So my question is why this app_ appears along with directory name. I know its default, but what actually it means?

And secondly, how can I create a sub-directory inside my directory i.e. app_custom in this case. if anyone knows please help me to understand this concept of getDir.

like image 950
AndroidDev Avatar asked May 25 '26 13:05

AndroidDev


2 Answers

As far as I think, automatic "app_" added to user created data folders avoid any conflicts with system predefined application folders (folders inside application data folder i.e. cache, contents, databases etc. which are automatically created).

One method to create a sub folder inside those "app_..." folders, get absolute path of "app_..." folder, append required folder name to that and create using mkdirs()

e.g.

File dir = new File(newFolderPath);
dir.mkdirs()

Note: sub folders do not get "app_..." prefix

like image 139
Tejasvi Hegde Avatar answered May 28 '26 02:05

Tejasvi Hegde


You can create a new Directory using the path that you are getting from getDir(),

        File file = getDir("custom", MODE_PRIVATE);
        String path = file.getAbsolutePath();
        File create_dir = new File(path+"/dir_name");
        if(!create_dir.exists()){
            create_dir.mkdir();
        }
like image 40
Lalit Poptani Avatar answered May 28 '26 03:05

Lalit Poptani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!