package file;
import java.io.File;
import java.io.IOException; public class getFilePath {
public static void main(String[] args) throws IOException
{
System.out.println("------默认相对路径,取得路径不同-----");
File f = new File("..\\src\\file");
System.out.println(f.getPath());
System.out.println(f.getAbsolutePath());
System.out.println(f.getCanonicalPath());
System.out.println("------默认相对路径,取得路径不同-----");
File f2 = new File(".\\src\\file");
System.out.println(f2.getPath());
System.out.println(f2.getAbsolutePath());
System.out.println(f2.getCanonicalPath());
System.out.println("------默认绝对路径,取得路径相同-----");
File f3 = new File("C:\\src\\file");
System.out.println(f3.getPath());
System.out.println(f3.getAbsolutePath());
System.out.println(f3.getCanonicalPath()); // 执行结果为:
// ------默认相对路径,取得路径不同-----
// ..\src\file
// C:\workspace\Tip\..\src\file
// C:\workspace\src\file
// ------默认相对路径,取得路径不同-----
// .\src\file
// C:\workspace\Tip\.\src\file
// C:\workspace\Tip\src\file
// ------默认绝对路径,取得路径相同-----
// C:\src\file
// C:\src\file
// C:\src\file
//
// 比较可以得到
// getPath()返回的是构造方法里的路径,不做任何处理
// getAbsolutePath()返回的是 user.dir+getPath(),也就是执行路径加上构造方法中的路径
// getCanonicalPath()返回的是将符号完全解析的路径,也就是全路径
}
}

file.getPath() getAbsolutePath() getCanonicalPath()区别的更多相关文章

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

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

  2. file的getPath getAbsolutePath和getCanonicalPath的区别

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

  3. file的getPath getAbsolutePath和getCanonicalPath的不同

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

  4. tomcat源码分析一之getCanonicalFile和getAbsolutePath的区别

    最近在看tomcat源码 1.getPath(): 返回定义时的路径,(就是你写什么路径,他就返回什么路径) 2.getAbsolutePath(): 返回绝对路径,但不会处理“.”和“..”的情况 ...

  5. File和FileStream的区别

    File和FileStream的区别直观点:File是一个静态类:FileStream是一个非静态类.File:是一个文件的类,对文件进行操作.其内部封装了对文件的各种操作(MSDN:提供用于创建.复 ...

  6. innodb log file与binlog的区别在哪里?

    Q: innodb log file与binlog的区别在哪里?有人说1.mysql的innodb引擎实际上是包装了inno base存储引擎.而innodb log file是由 inno base ...

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

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

  8. File.createNewFile和 File.createTempFile比较和区别

    原文地址:http://wzhiju.iteye.com/blog/1119037 最近,在看代码时看到了一个方法, File.createTempFile() ,由此联想到File.createNe ...

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

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

随机推荐

  1. nginx之编译安装

    一.认识nginx 常用的web服务有Apache.IIS(windows系统).Lighttpd.Tomcat.Nginx等.Nginx是一个开源的,支持高性能.高并发的www服务和代理服务软件.它 ...

  2. Android Studio中多项目共享Library

    FAQ: as的projectA中有一个commonLib的源码库模块,projectB要调用其中的commonLib, 这个有没有方案?不用手动拷贝aar的   方案1. 采用gradle配置参数方 ...

  3. Tcp协议三次握手四次挥手

    一.什么是TCP TCP(Transmission Control Protocol 传输控制协议)是一种面向连接(连接导向)的.可靠的. 基于IP的传输层协议.TCP在IP报文的协议号是6. 二.什 ...

  4. tar 命令显示进度条

    实现该功能需要安装 pv,然后把需要处理的数据通过管道传给 pv,最后再进行操作. 传给 pv 的目的是为了知道已经处理的数据量大小,同时需要通过 -s 指定总共需要处理的数据量大小. pv 的安装一 ...

  5. RF parameter

    There are primarily 3 features which can be tuned to improve the predictive power of the model : 说明: ...

  6. python3中SSLError错误处理

    在deepin中安装了python3.6,安装路径为/usr/local/python36,然后通过deepin自带的python2.7的pip安装了virtualenv: sudo pip inst ...

  7. Docker应用一:docker介绍

    Docker介绍与安装 一.Docker与传统虚拟化区别 直接看下图:                  传统虚拟化实现架构                                   doc ...

  8. graphviz 程序生成多种类型图表详解

    简介 一幅图抵得上千言万语,这在描述复杂的计算机系统时尤为正确.当系统环境变得更加复杂时,用图将它们表示出来并记入文档就显得更加重要.例如,虚拟化技术有很多优点,但它们通常会让环境变得更加复杂和更难理 ...

  9. spark-shell启动spark报错

    前言 离线安装好CDH.Coudera Manager之后,通过Coudera Manager安装所有自带的应用,包括hdfs.hive.yarn.spark.hbase等应用,过程很是波折,此处就不 ...

  10. 用户管理_组管理_权限管理.ziw

    2017年1月10日, 星期二 用户管理_组管理_权限管理 用户管理: useradd, userdel, usermod, passwd, chsh, chfn, finger, id, chage ...