getPath()与getAbsolutePath()的区别
2015-10-07 14:43
567 查看
getPath()与getAbsolutePath()的区别
public void diff_pathAndAbsolutePath(){
File file1 = new File(“.\test1.txt”);
File file2 = new File(“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得到的是构造参数的路径。
getAbsolutePath得到的是全路径。如果构造参数是相对路径,则返回当前目录的绝对路径+构造参数路径;如果是绝对路径则直接返回
public void diff_pathAndAbsolutePath(){
File file1 = new File(“.\test1.txt”);
File file2 = new File(“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得到的是构造参数的路径。
getAbsolutePath得到的是全路径。如果构造参数是相对路径,则返回当前目录的绝对路径+构造参数路径;如果是绝对路径则直接返回
相关文章推荐
- Yii2 使用十一 在设置enablePrettyUrl时候,defaultAction的设置方法
- PHPCMS常用函数[二次开发用]
- ajax+php如何获取部分请求的信息显示在对应的div中
- u-boot-2009.11移植(适用于TQ2440和MINI2440)第六篇:添加Yaffs(2)镜像烧写功能
- php的RSA加密解密算法
- php学习基础篇之文件函数库,序列化数据,文件包含
- 对php的简单概括
- PHP字符串操作
- Ubuntu 搭建ftp服务器
- ThinkPHP 6.使用上传模块(ajaxFileUpload)
- ZH奶酪:PHP抓取网页方法总结
- ZH奶酪:PHP 使用DOMDocument操作XML
- ZH奶酪:PHP 使用DOMDocument抓取网页
- php中的V->C传值,自动跳转页面,自动创建,数组的用法总结
- PHP Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity,
- ZH奶酪:PHP 执行时间Fatal error: Maximum execution time of...
- ZH奶酪:PHP (爬虫)下载图片
- Utf-8、gb2312都支持的汉字截取函数
- Laravel 学习笔记 —— 神奇的服务容器
- Thinkphp快速载入文本编辑器