【java】getAbsolutePath()方法详解
来源:互联网 发布:神雕群芳谱知乐改编 编辑:程序博客网 时间:2024/06/05 10:35
- 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.txt
- D:\workspace\test\.\test1.txt
- -----默认绝对路径:取得路径相同------
- D:\workspace\test\test1.txt
- D:\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.txt
- D:\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
- SylixOS入门指南--架设开发环境
- Vim命令合集(貌似有的有错误,Mark在这里,用到的时候来找)
- SpringMVC框架介绍
- 运行程序报错:the file"xxx"couldn't be open because you don't have permisslion to view it
- Objective-C 【在手动内存管理中如何写set方法】
- 【java】getAbsolutePath()方法详解
- 通过fetchXml 实现分页查询
- 干货分享!不得不看的【7年竞价实战经验总结】
- Linux系统下如何做到SSH免密码登录
- iOS UITableView显示下移问题:automaticallyAdjustsScrollViewInsets 属性浅谈
- kafka参数详解
- 天声人語
- Android不透明度16进制值
- 背景建模-均值法(Matlab)高斯背景建模(opencv)