执行代码时
File path = new File("/data");
boolean isDir = path.isDirectory();
//isDir is true
String[] fList = path.list();
//fList == null!
在 Android 2.3 模拟器上,文件列表为空。这似乎与文档 http://developer.android.com/reference/java/io/File.html#list 中的声明相矛盾():
Returns null if this file is not a directory.
这里有什么问题吗?
最佳答案
您无法访问 /data
目录,因为您没有 root 访问权限。如果没有 root 权限,您只能访问外部存储和内部存储中的应用程序目录。
看看这个答案:https://stackoverflow.com/a/1043722/1037294
关于java - File.list() 为目录返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10351749/