package xian;
import java.io.File;
import java.util.ArrayList;
public class GetFile {
private static ArrayList<String> fileList = new ArrayList<String>();
public static void main(String[] args) {
String filePath="E://小仙U盘";
getFiles(filePath);
}
/**
* 通过递归过得目录和文件
*/
public static void getFiles(String filePath){
File fileAll=new File(filePath);
File[] files=fileAll.listFiles();
for(File file:files){
if(file.isDirectory()){//如果是目录
//递归
getFiles(file.getAbsolutePath());
fileList.add(file.getAbsolutePath());
System.out.println("显示"+filePath+"下所有子目录及其文件"+file.getAbsolutePath());
}else{
System.out.println("显示"+filePath+"下所有子目录"+file.getAbsolutePath());
}
}
}
}
显示E:\小仙U盘\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn下所有子目录E:\小仙U盘\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn\btn-default-toolbar-small-focus-bg.gif
显示E:\小仙U盘\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn下所有子目录E:\小仙U盘\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn\btn-default-toolbar-small-focus-corners.gif
显示E:\小仙U盘\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn下所有子目录E:\小仙U盘\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn\btn-default-toolbar-small-focus-sides.gif
显示E:\小仙U盘\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn下所有子目录E:\小仙U盘\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn\btn-default-toolbar-small-over-bg.gif
显示E:\小仙U盘\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn下所有子目录E:\小仙U盘\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn\btn-default-toolbar-small-over-corners.gif