我目前正在处理内部存储。
我试图在内部存储中创建子目录,比如data/data/com.example.app/ parent文件夹/ 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);一些逻辑上的错误,它不能创建子文件夹,它反映了一些错误.
发布于 2017-06-20 06:58:00
,最后我得到了答案
//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);https://stackoverflow.com/questions/43013806
复制相似问题