private static class MyWalk extends DirectoryWalker
{
@Override
//目录处理
protected boolean handleDirectory(File directory, int depth, Collection results)
throws IOException
{
results.add("目录:"+directory.getPath()+":"+directory.getName());
return true;
}
@Override
//文件处理
protected void handleFile(File file, int depth, Collection results)
throws IOException
{
// TODO Auto-generated method stub
results.add("文件:"+file.getPath()+":"+file.getName());
}
public List<String> find(File startDirectory)
{
List<String> results = new ArrayList<String>();
try
{
walk(startDirectory, results);
}
catch (IOException e)
{
Assert.fail(e.toString());
}
return results;
}
}
public static void main(String[] args)
{
File src = new File("F:\\test\\bb"); //源目录
File desc = new File("F:\\test\\cc"); //子目录
try
{
FileUtils.copyDirectory(src, desc);
}
catch (IOException e)
{
e.printStackTrace();
}
}
一个封装好的处理文件和目录