Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating directory in internal storage android

Tags:

java

android

Is it possible to create directory in directory. To create one directory simply call this:

File dir1 = getDir("dir1",Context.MODE_PRIVATE);

But how to create other directory in dir1 ?

this:

File dir2 =getDir("dir1"+"/"+"dir2",Context.MODE_PRIVATE);

throw exception:

File dirFile = java.lang.IllegalArgumentException: File app_dir1/dir2 contains a path separator

Thanks.

like image 443
Streetboy Avatar asked Jan 17 '23 16:01

Streetboy


1 Answers

The Context.getDir() appears to be an Android-unique method for abstracting out the process of creating a directory within the private storage area - it is not a generic way of making directories in general.

To make your child subdirectory, you should use normal java methods, such as

File dir2 =new File(dir1, "dir2").mkdir();

Note that the first parameter here is the File Object representing the first directory you created, not the name.

You may want to subsequently set the permissions on this directory.

warning: untested

like image 72
Chris Stratton Avatar answered Jan 20 '23 03:01

Chris Stratton