我想浏览设备上的所有文件,以查找所有以特定文件扩展名结尾的文件。如果我没有权限访问特定的文件夹,那我想跳过并继续下一个...我有执行File.walkTree和File.list()的代码,问题是我正在获取accessdeniedexception和File .list返回null。因此,我的Java问题是如何在设备中搜索以给定扩展名结尾的文件。
[请注意:我的PC上正在正确运行该代码,而我的设备或仿真器上未运行同一代码File f = Paths.get("/storage/self/primary/").toFile();
String files [] =f.list();
if (files!=null) {
Log.v(LOG_TAG,"clickRefresh..files array not null.."+files.length);
// For each pathname in the pathnames array
for (String pathname : files) {
// Print the names of files and directories
Log.v(LOG_TAG, "list=" + pathname);
}
}
else{
Log.v(LOG_TAG,"clickRefresh..so the files is null...");
}
上面的代码返回一个空的路径名..下面的代码在设备或模拟器上也不起作用,但是在我的PC上正常(减去Log.v)Files.walkFileTree(source, new MyFileVisitor());
下面包含我的权限: