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
系统推荐
- Oh My ZSH
- Redis笔记
- Git合并多个提交并push到远程仓库
- Spring Cloud Gateway收到的是http请求,但schema却是https
- 随记
- 是时候使用MapStruct替代BeanUtils了
- Thread & ExecutorService & ThreadPoolExecutor 总览
- istio基础知识
- index方法压力测试记录
- Lombok的Accessors导致EasyExcel读取失败
- GitHub Workflow突然报错
- WebSocket SpringBoot Demo
- 随机毒鸡汤:知道备胎为什么是圆的吗?因为方便滚啊。