这是我自己写的一个历遍目录的类,使用了递归方法,如果大家谁需要,就随便那去用吧!
import java.io.*;
import java.util.*;
public class ListDirectory {
public static int listDir(String dir, ArrayList listFile) throws IOException {
int result = 0;
File file = new File(dir);
File fileList[];
if (!file.isDirectory()) {
result = -1;
} else {
fileList = file.listFiles();
for (int i=0; i<fileList.length; i++) {
if (fileList[i].isDirectory()) {
listDir(fileList[i].getPath(), listFile);
} else {
listFile.add(fileList[i].getPath());
}
}
}
return result;
}
}
递归历遍目录
最新推荐文章于 2024-08-24 10:23:45 发布