getPath(),getAbsolutePath(),getCanonicalPath()简介说明

戚薇 Java经验 发布时间:2023-05-24 21:21:40 阅读数:18591 1
下文笔者将通过示例的方式讲述getPath(),getAbsolutePath(),getCanonicalPath()的功能简介,如下所示

getPath(),getAbsolutePath(),getCanonicalPath()简介

getPath():
   直接返回构造 java.io.File 实例时使用的路径参数
getAbsolutePath():
   返回绝对路径,但不会处理相对路径符号 [.] 和 [..]
getCanonicalPath():
   返回规范的绝对路径,即是绝对也是唯一

getPath(),getAbsolutePath(),getCanonicalPath()示例

package com.java265.other;

import java.io.File;
import java.io.IOException;

public class Test21 {
	/**
	 * java265.com
	 * 
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		File file = new File("./test.txt");
		System.out.println(file.getPath());
		System.out.println(file.getAbsolutePath());
		System.out.println(file.getCanonicalPath());
	}
}
getPath(),getAbsolutePath(),getCanonicalPath()简介说明
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

本文链接: https://www.Java265.com/JavaJingYan/202305/16849345606617.html

最近发表

热门文章

好文推荐

Java265.com

https://www.java265.com

站长统计|粤ICP备14097017号-3

Powered By Java265.com信息维护小组

使用手机扫描二维码

关注我们看更多资讯

java爱好者