String folderPath = Environment.getExternalStorageDirectory() + "/AllAroundMe/Images";
File file = new File(folderPath);
if(!file.exists())
{
if(file.mkdirs());
Log.d("MyTag","Created folders succefully");
}
if(file.exists())
{
Log.d("MyTag", "folders exists: " + file.getAbsolutePath());
}
条件里的第二个if语句没有执行到,但是我做了文件目录,应该被执行到。是我的代码不对吗?
每次我执行这个程序的时候,总是一直在执行第一个条件。
确保在 android.manifest 文件中有:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
然后再创建一个文件对象:
String folderPath = "AllAroundMe/Images";
File file = new File(Environment.getExternalStorageDirectory(), folderPath);
目录路径最后加个正斜杠/