以下实例演示了使用 File 类的 file.getName() 和 file.listFiles() 方法来打印目录结构:
import java.io.File;
import java.io.IOException;
public class FileUtil {
public static void main(String[] a)throws IOException{
showDir(1, new File("d:\\Java"));
}
static void showDir(int indent, File file) throws IOException {
for (int i = 0; i
以上代码运行输出结果为:
-Java -----codes ---------string.txt ---------array.txt -----w3cschoolcc
自学教程