首页 > 其他 > 详细

递归显示指定文件夹下所有pdf文件

时间:2015-04-23 15:55:41      阅读:231      评论:0      收藏:0      [点我收藏+]

import java.io.File;
public class readFile {
  public static void main(String[] args) throws Exception {
    //递归显示C盘下所有文件夹及其中文件
    File root = new File("C:/Users/Administrator/Desktop");
    showAllFiles(root);
  }
  public static void showAllFiles(File dir) throws Exception{
    File[] fs = dir.listFiles();
    for(int i=0; i<fs.length; i++){
      if(fs[i].isDirectory()){
          try{
           showAllFiles(fs[i]);
          }catch(Exception e){}
      }else{
       String ffHouZhui=fs[i].getName().substring(fs[i].getName().lastIndexOf(".")+1,fs[i].getName().length());//后缀名
       if(ffHouZhui.equals("pdf")){//pdf文件
        System.out.println(fs[i].getName());
       }
      }
    }
   }
}

递归显示指定文件夹下所有pdf文件

原文:http://7883830.blog.51cto.com/7873830/1637549

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!