getPath()与getAbsolutePath()的区别
public void diff_pathAndAbsolutePath(){
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

结论:
getPath得到的是构造参数的路径。
getAbsolutePath得到的是全路径。如果构造参数是相对路径,则返回当前目录的绝对路径+构造参数路径;如果是绝对路径则直接返回

getPath的更多相关文章

  1. java中File类的getPath(),getAbsolutePath(),getCanonicalPath()区别

    File file = new File(".\\test.txt"); System.out.println(file.getPath()); System.out.printl ...

  2. getResource().getPath()返回的路径空格变成了 %20

    this.getClass().getResource(“/”).getPath()使用者方法查看文件在服务器上的地址,但是地址中的空格会被转化为%20. 解决办法1: URI uri = new U ...

  3. File和URL的getPath()方法区别

    java.io.File对象的getPath()方法返回文件的全路径名.如果是目录返回目录路径且结尾没有"\".如果是文件包含文件名. java.io.File对象的getName ...

  4. file的getPath getAbsolutePath和getCanonicalPath的不同

    file的这几个取得path的方法各有不同,下边说说详细的区别 概念上的区别:(内容来自jdk,个人感觉这个描述信息,只能让明白的人明白,不明白的人看起来还是有点难度(特别试中文版,英文版稍好些)所以 ...

  5. 关于File.getPath,File.getAbsolutePath,File.getCanonicalPath的区别

    这个问题, 不了解一下还是挺恍惚它们之间的区别的. 其实也挺简单的. getPath()-->>new File()时的路径 getAbsolutePath()-->>当前路径 ...

  6. file的getPath getAbsolutePath和getCanonicalPath的区别

    转自:http://www.blogjava.net/dreamstone/archive/2007/08/08/134968.html file的这几个取得path的方法各有不同,下边说说详细的区别 ...

  7. URL包里的URL.getpath()对路径中空格识别为%20的处理办法

    方法(1),使用repaceAll("%20",' ')替换后,只能解决空格问题.但是路径中包含%和中文就不行了. 方法(2),使用URLDecoder.decode(str,&q ...

  8. file.getPath() getAbsolutePath() getCanonicalPath()区别

    package file; import java.io.File; import java.io.IOException; public class getFilePath { public sta ...

  9. URL的getFile()和getPath()方法的区别(转)

    转自博客:http://blog.csdn.net/l375852247/article/details/7999063 import java.net.MalformedURLException; ...

  10. 关于Class类的getResource().getPath()方法

    程序中配置文件如果放置在classes文件夹,那么我们就可以使用Class类的getResource().getPath()方法获取文件路径. 例如: String path = DBUtil.cla ...

随机推荐

  1. 记录zabbix4.0升级4.2

    系统环境 [root@localhost ~]# cat /etc/redhat-release CentOS release 6.9 (Final) 官方网站       官方文档升级其实很简单如果 ...

  2. switch 语句 总结笔记

    1.switch 语句 语法: switch(expression) { case value1 : statement1; break; case value2 : statement2; brea ...

  3. 【EasyUI总结】EasyUI开发中遇到的坑

    普遍: 1.easyui在书写键值对的时候要注意是否要加引号,在需要加引号的地方不加则无法渲染: datagrid数据网格: 1.datagrid默认请求方式是post,如果要使用分页功能pagina ...

  4. C#面向对象详解

    //封装就是将数据或函数等集合在一个个的单元中,我们称之为类,被封装的对象通常被称为抽象数据类型, //封装的意义在于保护或防止代码被我们无意中破坏, //封装既可以封装成员变量,又可以封装成员方法, ...

  5. 三维偏序[cdq分治学习笔记]

    三维偏序 就是让第一维有序 然后归并+树状数组求两维 cdq+cdq不会 告辞 #include <bits/stdc++.h> // #define int long long #def ...

  6. [PAT] A1023 Have Fun with Numbers

    [题目大意] 给一个不超过20位的数字,如果将它乘以2得到的数仅仅是原来的数字重新排列得到的,那就输出Yes,下一行输出加倍后的数.如果不是,输出No,下一行输出加倍后的数. [思路] 20位过于庞大 ...

  7. input清空和重置select下拉框

    背景 一般页面搜索条件都会有input输入框和select选择框,同时页面上都会有重置reset按钮,这时就需要清空input和重置select 实现 清空input 清空单个input: $(&qu ...

  8. Ceph集群网络切换

    背景:需要对已部署好的Ceph集群切换网络,包含包含公共网络和集群网络 1 关闭所有mon节点的mon服务并修改服务器IP systemctl stop ceph-mon@storage01.serv ...

  9. 使用phpstudy向mysql中导入数据

  10. PHP0003:PHP基础2

    die表示结束,程序到此运行不过来了. 字符串比较是挨个比较