我目前正在使用内部存储空间
我正在尝试在内部存储中创建子目录,例如 data / data / com.example.app / parentfolder / childfolder / sample.mp4
我的代码是
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);
有些逻辑错误,它不能创建子文件夹,它反映了一些错误....
答案 0 :(得分:0)
File file = new File(location);
file.mkdirs();
答案 1 :(得分:0)
最后我得到答案
//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);