getPath()与getAbsolutePath()的区别

测试代码如下

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()); 

	}
}

运行结果

猜你喜欢

转载自blog.csdn.net/qq_42651904/article/details/81209010