我在一個listActivity中工作,我試圖顯示給定目錄的子項。下面是我試圖獲得給定目錄的孩子:file.lis()返回「null」,儘管它不應該
File currentFile = new File(Environment.getExternalStorageDirectory(), "Pictures");
String[] children = currentFile.list();
事實上,「孩子」是空,我不知道爲什麼。當我詢問「currentFile」的絕對路徑時,答案是「/ storage/emulated/0/Pictures」。
感謝您的幫助!
文件稱**結果爲空,如果這個文件不是一個目錄**。嘗試'File path = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES);' – Raghunandan
只需添加'if(currentFile.exists()&& currentFile.isDirectory()){String [] children = currentFile.list(); }「檢查你的自我 –
謝謝你的回答,但它不起作用: 」currentFile.exists()「返回」true「, 」currentFile.isDirectory()也返回「true」,但仍然 「children = = null「返回」真「... –