【java】getAbsolutePath()方法详解
来源:互联网 发布:apache impala 编辑:程序博客网 时间:2024/06/05 08:18
getAbsolutePath():返回抽象路径名的绝对路径名字符串。public static void test1(){ 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.txtD:\workspace\test\.\test1.txt-----默认绝对路径:取得路径相同------D:\workspace\test\test1.txtD:\workspace\test\test1.txt----------------------------------------------------public static void test2() throws Exception{ File file = new File("..\\src\\test1.txt"); System.out.println(file.getAbsolutePath()); System.out.println(file.getCanonicalPath()); }D:\workspace\test\..\src\test1.txtD:\workspace\src\test1.txt--------------------------------------------public static void test3() throws Exception{ File file = new File("D:\\Text.txt"); System.out.println(file.getCanonicalPath()); }(1),确定D盘下没有Text.txt这个文件,直接执行这段代码,得到的结果是:D:\Text.txt注意这里试大写的Text.txt(2)在D盘下建立一个文件,名叫text.txt,再次执行代码,得到结果D:\text.txt同样的代码得到不同的结果。
0 0
- 【java】getAbsolutePath()方法详解
- 【java】getAbsolutePath()方法详解
- Java中getAbsolutePath()实例详解
- Java中file类getPath(),getAbsolutePath(),getCanonicalPath()方法区别
- Java中file类getPath(),getAbsolutePath(),getCanonicalPath()方法区别
- Java中file类getPath(),getAbsolutePath(),getCanonicalPath()方法区别
- Java getPath() getAbsolutePath() getCanonicalPath()区别
- Java中getAbsolutePath()什么意思?
- java.io.File 中 getPath(), getAbsolutePath() 和 getCanonicalPath() 三个方法的区别
- java.io.File 中 getPath(), getAbsolutePath() 和 getCanonicalPath() 三个方法的区别
- java.io.File 中 getPath(), getAbsolutePath() 和 getCanonicalPath() 三个方法的区别
- java.io.File 中 getPath(), getAbsolutePath() 和 getCanonicalPath() 三个方法的区别
- java中file类的三种获取路径的方法getPath(),getAbsolutePath(),getCanonicalPath()的比较
- java里getPath、 getAbsolutePath、getCanonicalPath的区别
- java里getPath、 getAbsolutePath、getCanonicalPath的区别
- java中getpath、getabsolutepath和getname
- Java中getPath与getAbsolutePath区别
- topics: Java file getPath getAbsolutePath getCanonicalPath
- 新人报到
- 虚拟内存与虚拟地址空间
- 前端单选框实现父/子级包函选项功能
- poj 2155 Matrix
- netty5.0之server端NioServerSocketChannel的bind分析
- 【java】getAbsolutePath()方法详解
- Android中HandlerThread
- chrome浏览器卡死问题解决
- 冀该统梦捉倍易哨鞠揖锻逊
- UVA Master-Mind Hints()
- 关于Eclipse Adt插件删除不掉的解决方法!
- C#操作字符串方法总结<转>
- 在本地创建git库,提交到远程
- UVA List of Conquests(字符串按字典排序)