getPath vs getAbsolutePath vs getCanonicalPath
大约 2 分钟
getPath vs getAbsolutePath vs getCanonicalPath
getPath
以构造路径作为返回值
getAbsolutePath
以绝对路径作为返回值
getCanonicalPath
以绝对路径作为返回值(如果路径包含.或..会进行处理)
public static void main(String[] args){
File file1 = new File(".\\xxx.txt");
File file2 = new File("D:\\aaa\\xxx.txt");
System.out.println(file1.getPath());
System.out.println(file1.getAbsolutePath());
System.out.println(file1.getCanonicalPath());
System.out.println("------------------------");
System.out.println(file2.getPath());
System.out.println(file2.getAbsolutePath());
System.out.println(file2.getCanonicalPath());
}
输出如下内容:
.\xxx.txt
D:\aaa\.\xxx.txt
D:\aaa\xxx.txt
------------------------
D:\aaa\xxx.txt
D:\aaa\xxx.txt
D:\aaa\xxx.txt
系统推荐
- Notion笔记定时备份
- Docker进行资源隔离
- Spring Cloud(一):服务治理技术概览【Finchley 版】
- K8S 无感发布
- PasteImageIntoMarkdown插件开发
- JVM异常处理
- JVM杂项
- ES杂项
- Docker隐射的端口外网不能访问
- MySQL数据迁移到PGSQL
- CentOS7下Docker端口映射后防火墙失效
- raft协议
- 随机毒鸡汤:每一个抖腿的人,心里都有一台缝纫机。