java里getPath、 getAbsolutePath、getCanonicalPath的区别
来源:互联网 发布:打电话l录音软件 编辑:程序博客网 时间:2024/06/08 07:36
File的这三个方法在api中都有说明,仅以程序为例说明。
package test;
import Java.io.File;
import java.io.IOException;
public class TestFilePath {
}
程序执行结果如下:
F:\eclipseworkspace\testejb
-----默认相对路径:取得路径不同------
..\src\test1.txt
F:\eclipseworkspace\testejb\..\src\test1.txt
F:\eclipseworkspace\src\test1.txt
-----默认相对路径:取得路径不同------
.\test1.txt
F:\eclipseworkspace\testejb\.\test1.txt
F:\eclipseworkspace\testejb\test1.txt
-----默认绝对路径:取得路径相同------
D:\workspace\test\test1.txt
D:\workspace\test\test1.txt
D:\workspace\test\test1.txt
结论:
当输入为绝对路径时,返回的都是绝对路径。
当输入为相对路径时:
getPath()返回的是File构造方法里的路径,是什么就是什么,不增不减
getAbsolutePath()返回的其实是user.dir+getPath()的内容,从上面F:\eclipseworkspace\testejb、F:\eclipseworkspace\testejb\..\src\test1.txt、F:\eclipseworkspace\testejb\.\test1.txt可以得出。
getCanonicalPath()返回的就是标准的将符号完全解析的路径- java里getPath、 getAbsolutePath、getCanonicalPath的区别
- java里getPath、 getAbsolutePath、getCanonicalPath的区别
- java里getPath、 getAbsolutePath、getCanonicalPath的区别
- java里getPath、 getAbsolutePath、getCanonicalPath的区别
- java里getPath、 getAbsolutePath、getCanonicalPath的区别
- Java getPath() getAbsolutePath() getCanonicalPath()区别
- getPath(),getAbsolutePath(),getCanonicalPath()区别
- java中File类的getPath(),getAbsolutePath(),getCanonicalPath()区别
- java中File类的getPath(),getAbsolutePath(),getCanonicalPath()区别
- java中File类的getPath(),getAbsolutePath(),getCanonicalPath()区别
- java中File类的getPath(),getAbsolutePath(),getCanonicalPath()区别
- java中File类的getPath(),getAbsolutePath(),getCanonicalPath()区别
- 【java】File,file.getPath(), getAbsolutePath(), getCanonicalPath()区别
- getPath getAbsolutePath和getCanonicalPath的区别
- getPath getAbsolutePath和getCanonicalPath的区别
- getPath getAbsolutePath和getCanonicalPath的区别
- File的getPath(),getAbsolutePath(),getCanonicalPath()区别
- getPath getAbsolutePath和getCanonicalPath的区别
- MAP、ENTRY、for()遍历
- 我喜欢的
- OpenCV练习第一弹
- git使用记录(持续更新中)
- LinuxC中的setitimer()函数用法
- java里getPath、 getAbsolutePath、getCanonicalPath的区别
- DRUID连接池的实用 配置详解
- JAVA 各种数据类型、各种类型转换
- nhibernate 加载对象失败
- 孕妇不能吃哪些食物?(协和妇产权威版)
- '#selector' does not refer to an '@objc' method,No method declared with Objective-C selector 'compos
- 什么人合适学习利用自媒体淘客来赚钱
- 如何在开启了log-bin的MySQL Server中创建FUNCTION
- MYSQL 1005 错误121问题