Javaでフォルダを再帰するサンプルコード
コードメモ:
import java.io.File;
import java.util.ArrayList;
public class FileSysCheck {
private static ArrayList filelist = new ArrayList();
public static void main(String[] args) {
long cr= System.currentTimeMillis();
reFileList(“E:\\java_startnews24");
System.out.println(System.currentTimeMillis() – cr);
}
public static void reFileList(String strPath) {
File dir = new File(strPath);
File[] files = dir.listFiles();
if (files == null)
return;
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
reFileList(files[i].getAbsolutePath());
} else {
String strFile = files[i].getAbsolutePath().toLowerCase();
System.out.println(“—“+strFile);
filelist.add(files[i].getAbsolutePath());
}
}
}
}