Fille类
File指文件也指文件夹
构造方法:
1.File(String pathname);
通过将给定路径名字字符串转换为抽象路径名来创建一个人新的File实例
String pathname="d:"+File.separator+"b";
File file=new File(pathname);//File.separator表示分隔符
`2. 根据 parent 路径名字符串和 child 路径名字符串创建一个新 File 实例。
File (String parent,String child)
String parentname="d:"+File.separator+"c";
String childname="c.txt";
File file2=new File(parentname,childname);
3.File(File parent, String child)
根据 parent 抽象路径名和 child 路径名字符串创建一个新 File 实例。
String pathname="d:"+File.separator+"b";
String childname="c.txt";
File file3=new File(file1,childname);
主要方法
// 主要方法
System.out.println("是否存在" + file1.exists());
System.out.println("获取文件名" + file1.getName());
System.out.println("绝对路径" + file1.getAbsolutePath());
System.out.println("获取父目录名" + file1.getParent());
File parentfile = file1.getParentFile();//获取父目录对象
System.out.println(parentfile.getName());