首页 > 系统 > Android > 正文

Android 遍历SDCARD的文件夹并显示目录信息

2019-12-12 02:39:41
字体:
来源:转载
供稿:网友

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";  }

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表