加上
File file = new File(System.getProperty("user.dir")); System.out.println(file); // get parent dir String parentPath1 = file.getParent(); System.out.println(parentPath1);感觉这个很好用,直接获得当前项目路径
System.out.println(System.getProperty("user.dir")); File file = new File(System.getProperty("user.dir")); System.out.println(file); // get parent dir String parentPath1 = file.getParent(); System.out.println(parentPath1); String toolPath = parentPath + "/tool"; System.out.println(toolPath); FileUtil.createFolderIfNotExist(toolPath); System.out.println(toolPath);这里加不加/都是可以的