file.getPath() VS getAbsolutePath() VS getCanonicalPath()
来源:互联网 发布:瀚资软件咨询有限公司 编辑:程序博客网 时间:2024/06/08 07:08
区别
- getPath()返回的是构造方法里的路径,不做任何处理;
- getAbsolutePath()返回的是 user.dir+getPath(),也就是执行路径/用户工作目录加上构造方法中的路径;
- getCanonicalPath()返回的是将符号完全解析的路径,也就是全路径;
代码示例
import java.io.File;public class FilePathTest { public static void main(String[] args) throws Exception { System.out.println("工作目录:" + System.getProperty("user.dir")); File f = new File("../tt.txt"); System.out.println("f.getPath(): " + f.getPath()); System.out.println("f.getAbsolutePath(): " + f.getAbsolutePath()); System.out.println("f.getCanonicalPath(): " + f.getCanonicalPath()); }}
输出结果:
工作目录:D:\projects\nettyf.getPath(): ..\tt.txtf.getAbsolutePath(): D:\projects\netty\..\tt.txtf.getCanonicalPath(): D:\projects\tt.txt
阅读全文
0 0
- file.getPath() VS getAbsolutePath() VS getCanonicalPath()
- File:getPath()&getAbsolutePath()&getCanonicalPath()
- file.getPath() getAbsolutePath() getCanonicalPath()区别
- file.getPath() getAbsolutePath() getCanonicalPath()区别
- file.getPath() getAbsolutePath() getCanonicalPath()区别
- 【java】File,file.getPath(), getAbsolutePath(), getCanonicalPath()区别
- File的getPath(),getAbsolutePath(),getCanonicalPath()区别
- topics: Java file getPath getAbsolutePath getCanonicalPath
- File类的getPath()、getAbsolutePath()、getCanonicalPath()
- getPath(),getAbsolutePath(),getCanonicalPath()区别
- getpath() & getAbsolutePath() & getCanonicalPath()
- file的getPath getAbsolutePath和getCanonicalPath的不同
- file的getPath getAbsolutePath和getCanonicalPath的不同
- JAVA中file的getPath getAbsolutePath和getCanonicalPath的不同
- file的getPath getAbsolutePath和getCanonicalPath的不同
- file的getPath getAbsolutePath和getCanonicalPath的不同
- file的getPath getAbsolutePath和getCanonicalPath的不同
- file的getPath getAbsolutePath和getCanonicalPath的不同
- Go源码分析 net/http包分析:追溯到socket
- gdb调试之函数篇
- Android播放flash
- 怎样保证max中的贴图和模型匹配,一起进入unity中?
- MySQL数据类型理解和优化
- file.getPath() VS getAbsolutePath() VS getCanonicalPath()
- xadmin遇到def save_models(self)的问题
- lua学习笔记(1)——lua简介和环境搭建
- CefSharp 集成谷歌浏览器详解---(一)环境搭建
- 文章标题 将图片从一个文件夹复制到另一个文件夹
- windows下共用JDK环境,同时启动多个tomcat具体步骤
- c和c++中&的用法及区别
- EasyMovieTexture使用总结
- Banner