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
系统推荐
- Docker进行资源隔离
- Nacos-Spring Gateway-Spring boot无感发布
- 随记
- 正则表达式匹配第几个符号问题
- Redis高可用
- 数据同步方案
- 推荐几个适用小工具
- Flutter开发需要涉及的知识点大纲
- Arthas使用记录
- 分布式事务Seata
- 表单重复提交解决方案
- Hbase 总览
- 随机毒鸡汤:所有人都抵不过时间,就像你偶然想起我,问我有没有钱。