Vijay
Vijay

Reputation: 247

Android create directory + sub (or) child directory in internal storage

I am currently working with internal storage

I am trying to create child directory in internal storage,like data/data/com.example.app/ parentfolder / childfolder / sample.mp4

Here my code was

    ContextWrapper cw = new ContextWrapper(context);
    File parentpath = cw.getDir("parentfolder ",Context.MODE_PRIVATE);
    File childpath = new File(parentpath ,"childfolder");
    File childfolder = new File(childpath,"sample.mp4");
    FileOutputStream fos = new FileOutputStream(childfolder);

Some logical mistake for that,its cannot create childfolder, Its reflect some error....

Upvotes: 0

Views: 1453

Answers (2)

Vijay
Vijay

Reputation: 247

And finally i got the answer

//Save Internal Storage

File myMainDir = context.getDir("MainFolder", Context.MODE_PRIVATE);

File mySubjectDir = new File(myMainDir, subFolder);
mySubjectDir.mkdir();

File myModuleDir = new File(mySubjectDir, semiSubFolder);
myModuleDir.mkdir();

File myFinalDir = new File(mySubjectDir, fileName);

//Save External Storage

String DNAME = "MainFolder"+"/"+subFolder+"/"+semiSubFolder;
File rootPath = new File(Environment.getExternalStorageDirectory().toString(), DNAME);
if(!rootPath.exists()) {
    rootPath.mkdirs();
}

if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
    Log.v("Cannot use storage","Cannot use storage");
}

File myFinalDir = new File(rootPath,TopicName);

Upvotes: 2

David Luque
David Luque

Reputation: 1108

File file = new File(location);
file.mkdirs();

Upvotes: 0

Related Questions