package com.king.coding;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
/**
* 递归法,获取文件夹中的文件
* @author Administrator
*
*/
public class JavaFilter implements FilenameFilter {
public static final String ROOT_PATH = "E:/j2ee/web开发/student/";
public static void main(String[] args) {
List<File> files = refreshFile(ROOT_PATH);
for(File file:files){
System.out.println(file.getName());
}
}
static List<File> allFiles = new ArrayList<File>();
public static List<File> refreshFile(String path){
File file = new File(path);
File[] files = file.listFiles();
if(null==files)
return null;
for(int i = 0;i<files.length;i++){
if(files[i].isDirectory()){
refreshFile(files[i].getAbsolutePath()); //注意这里的递归方法
}else{
if(files[i].getName().endsWith(".java"))
allFiles.add(files[i]);
}
}
return allFiles;
}
@Override
public boolean accept(File dir, String name) {
return false;
}
}
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
/**
* 递归法,获取文件夹中的文件
* @author Administrator
*
*/
public class JavaFilter implements FilenameFilter {
public static final String ROOT_PATH = "E:/j2ee/web开发/student/";
public static void main(String[] args) {
List<File> files = refreshFile(ROOT_PATH);
for(File file:files){
System.out.println(file.getName());
}
}
static List<File> allFiles = new ArrayList<File>();
public static List<File> refreshFile(String path){
File file = new File(path);
File[] files = file.listFiles();
if(null==files)
return null;
for(int i = 0;i<files.length;i++){
if(files[i].isDirectory()){
refreshFile(files[i].getAbsolutePath()); //注意这里的递归方法
}else{
if(files[i].getName().endsWith(".java"))
allFiles.add(files[i]);
}
}
return allFiles;
}
@Override
public boolean accept(File dir, String name) {
return false;
}
}