Android file.lis()返回";空";虽然它不应该';T

Android file.lis()返回";空";虽然它不应该';T,android,list,file,null,children,Android,List,File,Null,Children,我在一个listActivity中工作,我试图显示给定目录的子目录。以下是我试图获取给定目录的子目录的内容: File currentFile = new File(Environment.getExternalStorageDirectory(), "Pictures"); String[] children = currentFile.list(); 事实上,“children”是空的,我不知道为什么。当我询问“currentFile”的绝对路径时,答案是“/storage

我在一个listActivity中工作,我试图显示给定目录的子目录。以下是我试图获取给定目录的子目录的内容:

    File currentFile = new File(Environment.getExternalStorageDirectory(), "Pictures");
    String[] children = currentFile.list();
事实上,“children”是空的,我不知道为什么。当我询问“currentFile”的绝对路径时,答案是“/storage/simulated/0/Pictures”


谢谢你的帮助

确保文件夹存在,并检查您是否已将权限添加到清单中

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

如果您在安卓M上运行,则需要请求运行时权限


文档说,如果此文件不是目录,则结果为空。尝试
File path=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY\u图片)只需添加
if(currentFile.exists()&¤tFile.isDirectory()){String[]children=currentFile.list();}
检查您的自我谢谢您的答案,但它不起作用:“currentFile.exists()”返回“true”,“currentFile.isDirectory()也返回“true”,但仍然“children==null”返回“true”“…谢谢,但是我已经在我的清单中添加了权限(其他人在堆栈溢出上也有同样的问题),那么,你是在安卓M上运行吗?”?i、 e.版本23或android 6.0不,我不是,我的android版本只有5.0.2你试过emulator吗?此外,您可能希望在github上创建一个示例项目,这样我们可以更容易地提供帮助。