当前位置: 代码迷 >> Android >> android-SD卡-查看模拟卡中文件夹里的文件,该怎么处理
  详细解决方案

android-SD卡-查看模拟卡中文件夹里的文件,该怎么处理

热度:110   发布时间:2016-05-01 22:21:11.0
android-SD卡-查看模拟卡中文件夹里的文件
各位大虾:我现在想在写一个方法,主要是查询sd卡中某个特定文件夹下的文件名,查询结果放入List中。
求代码,急~~~

------解决方案--------------------
学习,帮顶,,,
------解决方案--------------------
写一个递归就好了

public void test(String str){
File file = new File(str);

if(file.isDirectory()){
File[] fl = file.listFiles();
for (int i = 0; i < fl.length; i++) {
test(fl.get(i).getName());
}
}else{
list.add(str);
}
}
------解决方案--------------------
估计楼主主要是不知道怎么读SD文件吧 两行代码就OK了啊
File home = new File(FILE_PATH);
if (home.listFiles(new MusicFilter()).length > 0)
{
for (File file : home.listFiles(new MusicFilter()))
{
String strName = file.getName();
..............
...............
}
}

class MusicFilter implements FilenameFilter
{
public boolean accept(File dir, String name)
{
//这里还可以设置其他格式的文件
return (name.endsWith(".xxx"));
}
}
  相关解决方案