列出1000多个目录和子目录中文件名的最快方法是什么?
编辑; 我使用的当前代码是:
import java.io.File;
public class DirectoryReader {
static int spc_count=-1;
static void Process(File aFile) {
spc_count++;
String spcs = "";
for (int i = 0; i < spc_count; i++)
spcs += " ";
if(aFile.isFile())
System.out.println(spcs + "[FILE] " + aFile.getName());
else if (aFile.isDirectory()) {
System.out.println(spcs + "[DIR] " + aFile.getName());
File[] listOfFiles = aFile.listFiles();
if(listOfFiles!=null) {
for (int i = 0; i < listOfFiles.length; i++)
Process(listOfFiles[i]);
} else {
System.out.println(spcs + " [ACCESS DENIED]");
}
}
spc_count--;
} …Run Code Online (Sandbox Code Playgroud) 简单:我如何读取Java中目录的内容,并将该数据保存在某种数组或变量中?其次,我如何用Java打开外部文件?