file.getCanonicalFile()获取标准路径,
file.getAbsolutePath()获取绝对路径,把new File(“path”)包含进去
package com.xcrj.path;
import java.io.File;
import java.io.IOException;
public class PathMain {
public static void main(String[] args) throws IOException {
// 设置为当前文件夹
File file = new File("");
// 标准路径,G:micro-servicespringbootbasic
System.out.println(file.getCanonicalFile());
// 绝对路径,G:micro-servicespringbootbasic
System.out.println(file.getAbsolutePath());
File file1 = new File("xcrj");
// 标准路径,G:micro-servicespringbootbasicxcrj
System.out.println(file1.getCanonicalFile());
// 绝对路径,G:micro-servicespringbootbasicxcrj
System.out.println(file1.getAbsolutePath());
// xcrj
System.out.println(file1.getPath());
// .代表当前路径
File file2 = new File(".");
// 标准路径,G:micro-servicespringbootbasic
System.out.println(file2.getCanonicalFile());
// 绝对路径,G:micro-servicespringbootbasic.
System.out.println(file2.getAbsolutePath());
// .
System.out.println(file2.getPath());
// .. 代表上1个路径
File file3 = new File("..");
// 标准路径,G:micro-service
System.out.println(file3.getCanonicalFile());
// 绝对路径,G:micro-servicespringbootbasic.。
System.out.println(file3.getAbsolutePath());
// .。
System.out.println(file3.getPath());
}
}



