html, body {
font-size: 15px;
}

body {
font-family: Helvetica, "Hiragino Sans GB", 微软雅黑, "Microsoft YaHei UI", SimSun, SimHei, arial, sans-serif;
line-height: 1.6;
color: ;
background-color: ;
margin: 0;
padding: 16px 20px;
}

h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
margin: 1.33rem 0 0.667rem;
padding: 0;
font-weight: bold;
}

h1 {
font-size: 21px;
font-size: 1.4rem;
}

h2 {
font-size: 20px;
font-size: 1.33rem;
}

h3 {
font-size: 18px;
font-size: 1.2rem;
}

h4 {
font-size: 17px;
font-size: 1.13rem;
}

h5 {
font-size: 15px;
font-size: 1rem;
}

h6 {
font-size: 15px;
font-size: 1rem;
color: #777777;
margin: 1rem 0;
}

div, p, ul, ol, dl, li {
margin: 0;
}
blockquote, table, pre, code{
margin: 8px 0;
}

ul, ol {
padding-left: 32px;
padding-left: 2.13rem;
}

blockquote {
border-left: 4px solid #dddddd;
padding: 0 12px;
padding: 0 0.8rem;
}

blockquote > :first-child {
margin-top: 0;
}

blockquote > :last-child {
margin-bottom: 0;
}

img {
border: 0;
max-width: 100%;
height: auto !important;
margin: 2px 0;
}

table {
border-collapse: collapse;
border: 1px solid #bbbbbb;
}

td {
padding:4px 8px;
border-collapse: collapse;
border: 1px solid #bbbbbb;
}

@media screen and (max-width: 660px) {
body {
padding: 20px 18px;
padding: 1.33rem 1.2rem;
}
}

@media only screen and (-webkit-max-device-width: 1024px), only screen and (-o-max-device-width: 1024px), only screen and (max-device-width: 1024px), only screen and (-webkit-min-device-pixel-ratio: 3), only screen and (-o-min-device-pixel-ratio: 3), only screen and (min-device-pixel-ratio: 3) {
html, body {
font-size: 17px;
}

body {
line-height: 1.7;
padding: 0.75rem 0.9375rem;
color: #353c47;
}

h1 {
font-size: 2.125rem;
}

h2 {
font-size: 1.875rem;
}

h3 {
font-size: 1.625rem;
}

h4 {
font-size: 1.375rem;
}

h5 {
font-size: 1.125rem;
}

h6 {
color: inherit;
}

ul, ol {
padding-left: 2.5rem;
}

blockquote {
padding: 0 0.9375rem;
}
}

file的这几个取得path的方法各有不同,下边说说详细的区别

file的这几个取得path的方法各有不同,下边说说详细的区别

概念上的区别:(内容来自jdk,个人感觉这个描述信息,只能让明白的人明白,不明白的人看起来还是有点难度(特别试中文版,英文版稍好些)所以在概念之后我会举例说明。如果感觉看概念很累就跳过直接看例子吧。看完例子回来看概念会好些。

getPath
public String getPath()将此抽象路径名转换为一个路径名字符串。所得到的字符串使用默认名称分隔符来分隔名称序列中的名称。 

返回:
此抽象路径名的字符串形式

getAbsolutePath
public String getAbsolutePath()返回抽象路径名的绝对路径名字符串。 
如 果此抽象路径名已经是绝对路径名,则返回该路径名字符串,这与 getPath() 方法一样。如果此抽象路径名是空的抽象路径名,则返回当前用户目录的 路径名字符串,该目录由系统属性 user.dir 指定。否则,使用与系统有关的方式分析此路径名。在 UNIX 系统上,通过根据当前用户目录分析某 一相对路径名,可使该路径名成为绝对路径名。在 Microsoft Windows 系统上,通过由路径名指定的当前驱动器目录(如果有)来分析某一相 对路径名,可使该路径名成为绝对路径名;否则,可以根据当前用户目录来分析它。 

返回:
绝对路径名字符串,它与此抽象路径名表示相同的文件或目录的 
抛出: 
SecurityException - 如果无法访问所需的系统属性值。
另请参见:
isAbsolute()

getCanonicalPath
public String getCanonicalPath()
                        throws IOException返回抽象路径名的规范路径名字符串。 
规 范路径名是绝对路径名,并且是惟一的。规范路径名的准确定义与系统有关。如有必要,此方法首先将路径名转换成绝对路径名,这与调 用 getAbsolutePath() 方法的效果一样,然后用与系统相关的方式将它映射到其惟一路径名。这通常涉及到从路径名中移除多余的名称(比 如 "." 和 "..")、分析符号连接(对于 UNIX 平台),以及将驱动器名转换成标准大小写形式(对于 Microsoft Windows 平台)。 

表 示现有文件或目录的每个路径名都有一个惟一的规范形式。表示非存在文件或目录的每个路径名也有一个惟一的规范形式。非存在文件或目录路径名的规范形式可能 不同于创建文件或目录之后同一路径名的规范形式。同样,现有文件或目录路径名的规范形式可能不同于删除文件或目录之后同一路径名的规范形式。 

返回:
表示与此抽象路径名相同的文件或目录的规范路径名字符串 
抛出: 
IOException - 如果发生 I/O 错误(可能是因为构造规范路径名需要进行文件系统查询) 
SecurityException - 如果无法访问所需的系统属性值,或者存在安全管理器,且其 SecurityManager.checkRead(java.io.FileDescriptor) 方法拒绝对该文件进行读取访问
从以下版本开始: 
JDK1.1 

二、例子:
1,getPath()与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

因为getPath()得到的是构造file的时候的路径。
getAbsolutePath()得到的是全路径
如果构造的时候就是全路径那直接返回全路径
如果构造的时候试相对路径,返回当前目录的路径+构造file时候的路径

2,getAbsolutePath()和getCanonicalPath()的不同

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

可以看到CanonicalPath不但是全路径,而且把..或者.这样的符号解析出来。
3,getCanonicalPath()和自己的不同。
就是解释这段话:

表 示现有文件或目录的每个路径名都有一个惟一的规范形式。表示非存在文件或目录的每个路径名也有一个惟一的规范形式。非存在文件或目录路径名的规范形式可能 不同于创建文件或目录之后同一路径名的规范形式。同样,现有文件或目录路径名的规范形式可能不同于删除文件或目录之后同一路径名的规范形式。 

单下边这段代码是看不到结果的,要配合一定的操作来看。下边操作步骤,同时讲解

public static void test3() throws Exception{
        File file = new File("D:\\Text.txt");
        System.out.println(file.getCanonicalPath());
    }

步骤:
确定你的系统是Windows系统。
(1),确定D盘下没有Text.txt这个文件,直接执行这段代码,得到的结果是:

D:\Text.txt

注意这里试大写的Text.txt
(2)在D盘下建立一个文件,名叫text.txt,再次执行代码,得到结果

D:\text.txt

同样的代码得到不同的结果。
同时可以对比getAbsolutePath()看看,这个得到的结果是一样的。

原因:
window 是大小写不敏感的,也就是说在windows上test.txt和Test.txt是一个文件,所以在windows上当文件不存在时,得到的路径就是按 照输入的路径。但当文件存在时,就会按照实际的情况来显示。这也就是建立文件后和删除文件后会有不同的原因。文件夹和文件类似。

三、最后:
1,尝试在linux下执行上边的步骤,两次打印的结果是相同的,因为linux是大小写敏感的系统。
2,手动删掉test.txt,然后尝试执行下边代码

public static void test4() throws Exception{
        File file = new File("D:\\Text.txt");
        System.out.println(file.getCanonicalPath());
        File file1 = new File("D:\\text.txt");
        file1.createNewFile();
        file = new File("D:\\Text.txt");
        System.out.println(file.getCanonicalPath());
    }
public static void test3() throws Exception{
        File file1 = new File("D:\\text.txt");
        file1.createNewFile();
        File file = new File("D:\\Text.txt");
        System.out.println(file.getCanonicalPath());
    }

执行上边两个函数,看看结果,然后思考一下为什么?
1,的结果是两个大写,
2,的结果试两个小写
连续两个大写的,是否跟上边的矛盾 ?
这是因为虚拟机的缓存机制造成的。第一次File file = new File("D:\\Text.txt");决定了结果.

file的这几个取得path的方法各有不同,下边说说详细的区别的更多相关文章

  1. open_basedir restriction in effect. File() is not within the allowed path(s)

    目前发现eaccelerator安装之后如果php.ini中设置open_basedir将导致open_basedir的一些报错(open_basedir restriction in effect. ...

  2. More than one file was found with OS independent path 錯誤

    More than one file was found with OS independent path 'lib/armeabi/libmrpoid.so',. 翻譯過來就是:在操作系統的獨立目錄 ...

  3. More than one file was found with OS independent path 'META-INF/LICENSE' | Error:Could not read \build\intermediates\typedefs.txt (系统找不到指定的文件。)

    FAQ1: Error:Could not read E:\new\PlatformLibrary\CommonLibrary\build\intermediates\typedefs.txt: E: ...

  4. 报错:Can't find a source file at "xxxxx“Locate the file or edit the source lookup path to include its location.

    调试问题: Can't find a source file at "/tmp/TI_MKLIB6sLCzz/SRC/exit.c" Locate the file or edit ...

  5. android异常 More than one file was found with OS independent path 'META-INF/XXX'

    android 异常总结:一个文件在jar包中出现多次. Error:Execution failed for task ':app:transformResourcesWithMergeJavaRe ...

  6. More than one file was found with OS independent path 'lib/armeabi-v7a/libgnustl_shared.so'

    More than one file was found with OS independent path 'xxx/xxx' 这个错误是在路径中出现了重复依赖. 解决办法是配置打包选项, 在 and ...

  7. python3 os.path.realpath(__file__) 和 os.path.cwd() 方法的区别

    python3 os.path.realpath(__file__) 和 os.path.cwd() 方法的区别 os.path.realpath 获取当前执行脚本的绝对路径. os.path.rea ...

  8. Linux遇到的问题(一)Ubuntu报“xxx is not in the sudoers file.This incident will be reported” 错误解决方法

    提示错误信息 www@iZ236j3sofdZ:~$ ifconfig Command 'ifconfig' is available in '/sbin/ifconfig' The command ...

  9. Message: 'geckodriver' executable needs to be in PATH. 解决方法

    问题描述: 执行如下代码 # coding=utf-8 from selenium import webdriver driver = webdriver.Firefox() driver.maxim ...

随机推荐

  1. 【转载】Oracle的方案(Schema)和用户(User)的区别

    免责声明:     本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除.     原文作者:立正_敬礼_喊志哥     原文地址:http://my.oschina.ne ...

  2. poj 2342 Anniversary party

    题目链接:http://poj.org/problem?id=2342 题意:读题很容易懂,这里不做介绍. 解法:树形DP之路的第一道题. #include<iostream> #incl ...

  3. 【BZOJ】【2809】【APIO2012】派遣dispatching

    贪心/可并堆 跪了……我这么弱果然还是应该回家种红薯去…… 考虑选人的时候,每个人对答案的贡献其实是一样的,都是1,那么我们就贪心地去选花钱少的就好啦~ 具体的做法:倒着枚举(因为有b[i]<i ...

  4. Leetcode#106 Construct Binary Tree from Inorder and Postorder Traversal

    原题地址 二叉树基本操作 [       ]O[              ] [       ][              ]O 代码: TreeNode *restore(vector<i ...

  5. 响应式嵌入 iframe Pym.js

    Pym.js 可以让你在嵌入 iframe 的时候可自动的对 iframe 的大小进行调整以适应父一层容器,并且可以避免跨域问题. 支持浏览器: Internet Explorer 9, 10 (Wi ...

  6. 两台机器间libevent通信:No route to host问题

    最近学习libevent库,遂在两台虚拟机间模拟通信,程序没逻辑错误,但客户端总是提示No route to host问题,想到可能是linux的防火墙问题导致的,于是关掉防火墙: Ubuntu系统防 ...

  7. 用fabric部署维护kle日志收集系统

    最近搞了一个logstash kafka elasticsearch kibana 整合部署的日志收集系统.部署参考lagstash + elasticsearch + kibana 3 + kafk ...

  8. MYSQL注入天书之宽字节注入

    Background-7 宽字节注入 Less-32,33,34,35,36,37六关全部是针对'和\的过滤,所以我们放在一起来进行讨论. 对宽字节注入的同学应该对这几关的bypass方式应该比较了解 ...

  9. Chapter 5

    1. 2模块导入 3.包导入

  10. .net 类型源码下载地址

    原文:http://www.cnblogs.com/ProJKY/p/SSCLI.html 一般场景下,采用 Reflector可以反射出.NET 的部分实现出来,可以拿来参考,但和微软公开的SSCL ...