绝对路径:从盘符开始
File f = new File("D:\\test\a.txt");
相对路径:相对当前项目下的路径
File f = new File("模块名\\a.txt")
public static void main(String[] args) throws IOException { // 绝对路径 File f = new File("C:\\a.txt"); System.out.println(f.createNewFile()); // 相对路径:项目下的a.txt File f1 = new File("a.txt"); System.out.println(f1.createNewFile()); // 相对路径:项目下的src\\com\\unit1\\test模块下的a.txt File f2 = new File("src\\com\\unit1\\test\\a.txt"); System.out.println(f2.createNewFile()); }