File类
1.1概述
1、它是文件和目录路径名的抽象表示
2、文件和目录是可以通过File封装成对象的
3、对于File而言,其封装的并不是一个真正存在的文件,仅仅是一个路径名而已。它可以是存在的,也可以是不存在的。将来是要通过具体的操作把这个路径的内容转换为具体存在的。
// 文件路径名
String pathname = "D:\\aaa.txt";
File file1 = new File(pathname);
// 文件路径名
String pathname2 = "D:\\aaa\\bbb.txt";
File file2 = new File(pathname2);
// 通过父路径和子路径字符串
String parent = "d:\\aaa";
String child = "bbb.txt";
File file3 = new File(parent, child);
// 通过父级File对象和子路径字符串
File parentDir = new File("d:\\aaa");
String child = "bbb.txt";
File file4 = new File(parentDir, child);
递归
public class Demo {
public static void main(String[] args) {
f1();
System.out.println("a");
}
private static void f1() {
f2();
System.out.println("b");
}
private static void f2() {
f3();
System.out.println("c");
}
private static void f3() {
System.out.println("d");
}
}