import java.io.*;
class Test1
{
public static void main(String[] args) throws Exception
{
String dir="F:\\demo";
File file=new File(dir);
copy(file);
}
public static void copy(File file) throws Exception
{
File[] names=file.listFiles(new FilenameFilter(){
public boolean accept(File file,String name)//记住传递参数的时候要带上参数的类型
{
return name.toString().endsWith(".java");
}
});
for(File name:names)
{
if(name.isDirectory());
copy(name);//如果是文件夹就继续遍历
System.out.println(name.getName());
}
}
}
|
|