Java中getPath,getAbsolutePath和getCanonicalPath区别

方法说明
getPath以构造路径作为返回值
getAbsolutePath以当前路径+构造路径作为返回值
getCanonicalPath以全路径作为返回值(如果构造路径包含.或…,会进行处理)

需要理解一下Canonical单词含义

在这里插入图片描述
测试示例

public static void main(String[] args) throws IOException {File file1 = new File("./hello.txt");File file2 = new File("/Users/caowei/hello.txt");System.out.println("-----默认相对路径:取得路径不同------");System.out.println(file1.getPath());System.out.println(file1.getAbsolutePath());System.out.println(file1.getCanonicalPath());System.out.println("-----默认绝对路径:取得路径相同------");System.out.println(file2.getPath());System.out.println(file2.getAbsolutePath());System.out.println(file2.getCanonicalPath());SpringApplication.run(Demo4Application.class, args);
}结果如下-----默认相对路径:取得路径不同------
./hello.txt
/Users/caowei/workspace/gitee/demo4/./hello.txt
/Users/caowei/workspace/gitee/demo4/hello.txt
-----默认绝对路径:取得路径相同------
/Users/caowei/hello.txt
/Users/caowei/hello.txt
/Users/caowei/hello.txt

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/414818.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

工作220:git clone的时候地址需要改成自己的用户名

git在clone地址的时候用户名 要写成自己 才能clone

Android 检查版本更新 Server后台下载

问题来了,平时开发应用也许你会遇到这种场景:应用启动检查服务器版本,若大于当前版本,则要从网络上下载APK文件,并在Activity上展示进度条。 版本更新,无非是下载apk文件,安装apk。 //其中用到…

[Tomcat报错]SEVERE: Error listenerStart

系统版本:CentOS 6.6 x64 java版本:1.7.0_55 问题描述: 迁移Tomcat工程启动后日志出现报错,内容如下: Jan 20, 2018 7:02:50 PM org.apache.catalina.core.StandardContext startInternal SEVERE: Error listenerStart…

error: style attribute '@android:attr/windowEnterAnimation' not found

是的在导入一个依赖的时候又报错了,除了上面这个下面还有几句类似的,解决方法很简单 在gradle.properties这个文件中添加如下一行代码即可: android.enableAapt2false 1这条语句关闭了Aapt2编译。

工作221:控制弹出框不全屏

<el-dialog :title"fullTitle" width"80%" :fullscreen"false" :close-on-click-modal"false" :visible.sync"dialogFormVisible"close"close"> 控制弹出框不全屏

Activity中 onResume和onPause与onStart()和onStop()的一些思考

也许你会遇到这种问题&#xff1a; 如果一个Activity在用户可见时才处理某个广播&#xff0c;不可见时注销掉&#xff0c;那么应该在哪两个生命周期的回调方法去注册和注销BroadcastReceiver呢&#xff1f; 下面见答案。 首先你要首先了解Activity的四种状态&#xff1a; ① Ac…

Ubuntu16.04安装搜狗输入法后有黑边问题的解决方法

apt-get install compton compton -b 转载于:https://www.cnblogs.com/xiaoyafei/p/8383678.html

glyphicons 图标大全

http://www.runoob.com/bootstrap/bootstrap-glyphicons.html

java打印运行时间

// 放在要检测的代码段前&#xff0c;取开始前的时间戳 Long startTime System.currentTimeMillis(); // 放在要检测的代码段后&#xff0c;取结束后的时间戳 Long endTime System.currentTimeMillis();// 计算并打印耗时 Long tempTime (endTime - startTime); System.out.…

工作222:title写活

<el-dialog:title"fullTitle":visible.sync"dialogFormVisible"close"close">

Java_WEB项目OOM(OutOfMemError内存溢出) MyEclipse配置Jvm内存

前言 刚刚接触的项目是基于SSM&#xff0c;但Tomcat启动时默认的64M内存就总显得不太够。程序运行过程中经常出现OOM(OutOfMemError)。 措施 搜索网上的解决方案&#xff0c;还是比较好解决的&#xff0c;需要给MyEclipse设置Jvm内存大小(即设置Tomcat的Jvm内存大小) : Win…

net.sf.ezmorph.Morpher问题解决

运行web项目&#xff0c;外部访问Servlet报错 报错如下&#xff1a; nested exception is java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher 找不到这个类&#xff1a;net.sf.ezmorph.Morpher 解决方法&#xff1a;复制这些servlet必要的jar包到WEB-INF文件夹下lib文…

记录自己灵感闪现的开发语录 每日更新 记录变强或者变得更菜的过程

坚持第1天 2018年8月5日 今日博客排名115万 1、大多数人不想成为菜鸟&#xff0c;但现实是大多数人是菜鸟&#xff0c;包括我。 坚持第2天 2018年8月6日 今日博客排名115万 1、听别人说&#xff1a;“大多数人吃得了生活的苦&#xff0c;却吃不了学习的苦”。而我现在&#xff…

工作223:状态管理里面取值

第一步 computed 第二步 取值 computed: {/*GY5 控制新增标题的显隐*/fullTitle() {return this.title "用户";},DepartmentId(){return this.$store.state.department.id},Property(){return this.$store.state.department.property}},created() {/*第二步*/ge…

jsp自定义alert

普通alert alert(data.msg); 自定义alert 1、创建弹出框div <!--弹出框---------------------------> <div id"alert_div" align"center"> <div align"left">操作提示</div> …

C语言实现排名算法和排位算法

1 #include "stdio.h"2 int search_second_max(int array[], int n,int m)3 {4 int max1;5 int i,num;6 num1;//默认第一名 7 if(m>n) return 0; 8 max1 array[m];9 for (i 0; i < n; i)10 {11 if (array[i]&g…

jeesite导出Excel Minimum column number is 0

问题今天在用jeesite(poi)做导出的时候遇到一些问题&#xff01;记录一下.java.lang.IllegalArgumentException: Minimum column number is 0 at org.apache.poi.ss.util.CellRangeAddressBase.validateColumn(CellRangeAddressBase.java:73) at org.apache.poi.ss.util.CellRa…

工作224:当前函数造成

这种报错一般是当前页面的create函数造成的

jQuery基础,javascript

1、获取标签id赋值 $("#data1").text("fwefewfewfwe"); 2、获取表单输入值 var data $("#myForm").serialize(); <input name"username" /></td> <input name"password" type"password"/&g…

在VirtualBox中安装BlackArch Linux

作者&#xff1a;荒原之梦安装前的准备 下载系统映像&#xff1a;BlackArch Linux官网下载页面 在本文中我使用的是BlackArch Linux的Live ISO&#xff0c;这样可以减少安装时下载系统的时间。BlackArch的Live ISO文件有7.5G&#xff0c;我们可以使用BT种子来下载&#xff0c;这…