在任何人将此标记为重复之前,我想让您知道我已经浏览了许多关于SO上的mkdirs()方法问题的问题,并且没有一个对我起作用,因此我认为我有一个特殊情况值得提问。
我尝试过使用mkdir(),更改了文件目录File的实例化。
我尝试过使用mkdir(),更改了文件目录File的实例化。
new File(Environment.getExternalStorageDirectory())
new File(Environment.getExternalStorageDirectory().getAbsolutePath())
new File(Environment.getExternalStorageDirectory(), "Directory")
new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "Directory")
new File(Environment.getExternalStorageDirectory().toString + "/Directory")
什么都不起作用。
注意:我在清单文件中也拥有WRITE_EXTERNAL_STORAGE
权限。
下面是我的代码片段:
File rootDirectory = new File(Environment.getExternalStorageDirectory(), getActivity().getPackageName());
File directory = new File(rootDirectory, "Directory");
if (!directory.exists()) {
if(directory.mkdirs()){
Log.d("log", "exists");
} else {
Log.d("log", "not exists");
}
}