现在的位置: 首页 > 综合 > 正文

用java实现获取某目录下的所有文件

2013年09月03日 ⁄ 综合 ⁄ 共 677字 ⁄ 字号 评论关闭

import java.io.File;

public class test {
    public static void main(String[] args) {
        String path="D:/javafile";
        test.print1(path);

    }

    public static void print1 (String path){
           File config=new File(path);
           File temp[];
           temp=config.listFiles();//列出目录下的文件及文件夹
           for(int i=0;i<temp.length;i++){
               if(temp[i].isDirectory()){//判断是否目录,如果是目录则递归回调继续处理改目录下的文件temp[i].getPath()
//                  System.out.println(temp[i].getPath()+": ");
                 print1(temp[i].getPath());
                  
               }
               else {
                  System.out.println(temp[i].getPath()+": ");
//                System.out.println(temp[i].getName());
               }
           }
        }    
}

抱歉!评论已关闭.