File类的概述
File更应该叫做一个路径,文件路径或者文件夹路径 ,路径分为绝对路径和相对路径
- 绝对路径:是一个固定的路径,从盘符开始
相对路径:相对于某个位置,在eclipse下是指当前项目下,在dos下
构造方法

File(String pathname):根据一个路径得到File对象/*** File(String pathname):根据一个路径得到File对象*/@Testpublic void demo1() {//File file = new File("folder_a\\a.txt");System.out.println(file.exists());//trueFile file2 = new File("b.txt");System.out.println(file2.exists());//trueFile file3 = new File("c.txt");System.out.println(file3.exists());//false}
File(String parent, String child):根据一个目录和一个子文件/目录得到File对象
/*** File(String parent, String child):根据一个目录和一个子文件/目录得到File对象*/@Testpublic void demo2() {String parent = "folder_b\\sub_b";String child = "file.txt";File file = new File(parent,child);System.out.println(file.exists());//true}
File(File parent, String child):根据一个父File对象和一个子文件/目录得到File对象
/*** File(File parent, String child):根据一个父File对象和一个子文件/目录得到File对象*/@Testpublic void demo3() {File parent = new File("folder_b\\sub_b");String child = "file.txt";File file = new File(parent, child);System.out.println(file.exists());//trueSystem.out.println(parent.exists());//true}
