java遍歷一個文件夾中的全部文件

public static void main(String[] args) {apache

               traverseFileFolders(new File("D:"));tomcat

            traverseFileFolders(new File("D:\\apache-tomcat-6.0.33\\conf"));spa

}get

public static void traverseFileFolders(File base){it

if(base!=null)traverseFileFolders(base.getAbsolutePath());file

}im

public static void traverseFileFolders(String path){static

path = StringUtils.trim(path);co

if(path==null)return;new

File file = new File(path);

if(!file.exists())return;

if(file.isFile())

{

System.out.print(file.getName()+":");

System.out.println(file.getAbsolutePath());

return;

}

File[] files = file.listFiles();

for(File each:files)

{

String eachPath = each.getAbsolutePath();

traverseFileFolders(eachPath);

}

}

相關文章
相關標籤/搜索