/** |
* 功能描述:列出某文件夹及其子文件夹下面的文件,并可根据扩展名过滤 |
* |
* @param path |
* 文件 |
*/ |
public static void list(File path) { |
if (!path.exists()) { |
System.out.println( "文件名称不存?" ); |
} else { |
if (path.isFile()) { |
if (path.getName().toLowerCase().endsWith( ".pdf" ) |
|| path.getName().toLowerCase().endsWith( ".doc" ) |
|| path.getName().toLowerCase().endsWith( ".chm" ) |
|| path.getName().toLowerCase().endsWith( ".html" ) |
|| path.getName().toLowerCase().endsWith( ".htm" )) { // 文件格式 |
System.out.println(path); |
System.out.println(path.getName()); |
} |
} else { |
File[] files = path.listFiles(); |
for ( int i = 0 ; i < files.length; i++) { |
list(files[i]); |
} |
} |
} |
} |