Android 遍历SDCARD Android 遍历SDCARD的文件夹并显示目录信息
人气:0想了解Android 遍历SDCARD的文件夹并显示目录信息的相关内容吗,在本文为您仔细讲解Android 遍历SDCARD的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android,遍历SDCARD的文件夹并,Android,遍历sd卡,下面大家一起来学习吧。
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"; }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
加载全部内容