Java文件夹遍历:
package com.xiva.demo.file;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
public class FileDemo {
private Set<String> directorySet = new HashSet<String>();
public void traversingDirectory(String filePath)
{
File file = new File(filePath);
if(file.isDirectory()){
directorySet.add(file.getAbsolutePath());
File[] fileArray = file.listFiles();
for (File subFile:fileArray) {
traversingDirectory(subFile.getAbsolutePath());
}
}
}
public static void main(String[] args)
{
FileDemo demo = new FileDemo();
demo.traversingDirectory("F:\\WorkSpace\\EclipseProjects\\MyJavaProject");
}
}
本次程序的目的是比较两个文件夹以及文件,然后进行Copy;test