getPath()与getAbsolutePath()的区别

437 阅读1分钟

测试代码如下

public class TextPath {

public static void main(String[] args) {

File file = new File("workspace\\test\\test1.txt");

//取得相对路径

System.out.println("Path: " + file.getPath());

//取得绝对路径

System.out.println("getAbsolutePath: " + file.getAbsolutePath());

}

}

运行结果