getCanonicalFile getAbsolutePath getPath
来源:互联网 发布:贝叶斯分类算法原理 编辑:程序博客网 时间:2024/06/06 14:20
package test;import java.io.File;import java.io.IOException;public class TestFilePath { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(System.getProperty("user.dir")); try { System.out.println("-----默认相对路径:取得路径不同------"); File file1 = new File("..\\src\\test1.txt"); System.out.println(file1.getPath()); System.out.println(file1.getAbsolutePath()); System.out.println(file1.getCanonicalPath()); System.out.println("-----默认相对路径:取得路径不同------"); File file = new File(".\\test1.txt"); System.out.println(file.getPath()); System.out.println(file.getAbsolutePath()); System.out.println(file.getCanonicalPath()); System.out.println("-----默认绝对路径:取得路径相同------"); File file2 = new File("D:\\workspace\\test\\test1.txt"); System.out.println(file2.getPath()); System.out.println(file2.getAbsolutePath()); System.out.println(file2.getCanonicalPath()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}程序执行结果如下:F:\eclipseworkspace\testejb-----默认相对路径:取得路径不同------..\src\test1.txtF:\eclipseworkspace\testejb\..\src\test1.txtF:\eclipseworkspace\src\test1.txt-----默认相对路径:取得路径不同------.\test1.txtF:\eclipseworkspace\testejb\.\test1.txtF:\eclipseworkspace\testejb\test1.txt-----默认绝对路径:取得路径相同------D:\workspace\test\test1.txtD:\workspace\test\test1.txtD:\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()返回的就是标准的将符号完全解析的路径
0 0
- getCanonicalFile getAbsolutePath getPath
- File:getPath()&getAbsolutePath()&getCanonicalPath()
- getPath()与getAbsolutePath()
- getPath、getAbsolutePath区别
- getPath(),getAbsolutePath(),getCanonicalPath()区别
- getpath() & getAbsolutePath() & getCanonicalPath()
- Java getPath() getAbsolutePath() getCanonicalPath()区别
- getPath()与getAbsolutePath()的区别
- file.getPath() getAbsolutePath() getCanonicalPath()区别
- file.getPath() getAbsolutePath() getCanonicalPath()区别
- file.getPath() getAbsolutePath() getCanonicalPath()区别
- getPath getAbsolutePath和getCanonicalPath的不同
- getPath getAbsolutePath和getCanonicalPath的区别
- getPath getAbsolutePath和getCanonicalPath的区别
- getPath getAbsolutePath和getCanonicalPath的区别
- java里getPath、 getAbsolutePath、getCanonicalPath的区别
- java里getPath、 getAbsolutePath、getCanonicalPath的区别
- java中getpath、getabsolutepath和getname
- button标题点击大小变化
- 单链表的实现
- MySQL 只能用localhost不能用ip连接
- java程序中加入@SuppressWarnings("serial")是什么意思?
- cs231n assignment1--Softmax
- getCanonicalFile getAbsolutePath getPath
- ASTableNode+MJRefresh教程
- ch5 link analysis
- 深入嵌入式系统的bootloader
- iOS NSObject中forwardInvocation消息重定向
- Node.js简介
- [Spring实战系列]
- Unit 4-Lecture 5: Expectation
- Android属性动画完全解析(上),初识属性动画的基本用法