Android 遍历SDCARD的文件夹并显示目录信息
程序员文章站
2023-11-29 19:58:52
android 遍历sdcard的文件夹并显示目录信息
private string mresult = new string(); private string...
android 遍历sdcard的文件夹并显示目录信息
private string mresult = new string(); private string[] mfilelist = null;
1)、显示所有文件/
file flist = new file("/mnt/sdcard"); mfilelist = flist.list(); for(string str: mfilelist){ mresult += str; mresult += "\n"; } textview tv = (textview)findviewbyid(r.id.result);
tv.settext(mresult.tostring());
2)、显示指定后缀名的文件/
filenamefilter fnf = new filenamefilter(){ public boolean accept(file dir, string filename) { if(filename.endswith(".mp3")) return true; return false; } }; mfilelist = flist.list(fnf); for(string str: mfilelist){ mresult += str; mresult += "\n"; }
3)、仅显示目录/
filefilter ff = new filefilter(){ public boolean accept(file pathname) { return pathname.isdirectory(); } }; file[] filedir = flist.listfiles(ff); for (int i = 0; i < filedir.length; i++) { string str = filedir[i].getname(); mresult += str; mresult += "\n"; }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
上一篇: 弄清笔记本电池爆炸原因防患于未然