getPath()与getAbsolutePath()
2016-02-22 18:55
621 查看
publicstaticvoidtest1(){
Filefile1=newFile(".\\test1.txt");
Filefile2=newFile("D:\\workspace\\test\\test1.txt");
System.out.println("-----默认相对路径:取得路径不同------");
System.out.println(file1.getPath());
System.out.println(file1.getAbsolutePath());
System.out.println("-----默认绝对路径:取得路径相同------");
System.out.println(file2.getPath());
System.out.println(file2.getAbsolutePath());
}
得到的结果:
-----默认相对路径:取得路径不同------
.\test1.txt
D:\workspace\test\.\test1.txt
-----默认绝对路径:取得路径相同------
D:\workspace\test\test1.txt
D:\workspace\test\test1.txt
因为getPath()得到的是构造file的时候的路径。
getAbsolutePath()得到的是全路径
如果构造的时候就是全路径那直接返回全路径
如果构造的时候试相对路径,返回当前目录的路径+构造file时候的路径
Filefile1=newFile(".\\test1.txt");
Filefile2=newFile("D:\\workspace\\test\\test1.txt");
System.out.println("-----默认相对路径:取得路径不同------");
System.out.println(file1.getPath());
System.out.println(file1.getAbsolutePath());
System.out.println("-----默认绝对路径:取得路径相同------");
System.out.println(file2.getPath());
System.out.println(file2.getAbsolutePath());
}
得到的结果:
-----默认相对路径:取得路径不同------
.\test1.txt
D:\workspace\test\.\test1.txt
-----默认绝对路径:取得路径相同------
D:\workspace\test\test1.txt
D:\workspace\test\test1.txt
因为getPath()得到的是构造file的时候的路径。
getAbsolutePath()得到的是全路径
如果构造的时候就是全路径那直接返回全路径
如果构造的时候试相对路径,返回当前目录的路径+构造file时候的路径
相关文章推荐
- PhpStorm 配置在浏览器中打开文件
- PHP初学之控制结构
- PHP初学之运算符
- 自定义ContentProvider
- 数据存储ContentProvider
- 关于CRTP(Curiously Recurring Template Prattern)的使用
- YII2
- ContentProvider应用组件实例记录
- RTP timestamp与帧率及时钟频率的关系
- php emoji表情处理
- php设置cookie,在js中如何获取
- 使用PHP+Sphinx建立高效的站内搜索引擎
- ftp虚拟用户的配置
- php-fpm upstream sent too big header while reading response header from upstream
- PHP调试的强悍利器之PHPDBG
- php中json_decode()和json_encode()的使用方法
- php strcmp()函数
- php 小数整理,向上取整,向下去整,四舍五入,丢弃小数部分,保留整数部分
- Laravel 文档中的 Service Providers
- 解决log4j:WARN Error initializing output writer. log4j:WARN Unsupported encoding?的问题