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);