Reputation: 247
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
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