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. 开发EXTMVC框架前需要了解的基础知识整理

    1.组件选择器 目的:了解如何选择Extjs中的组件,就跟学习jquery时一定会先要学习:$()选择器一样. 常用场景:       1.在controller中的control事件中用到      ...

  2. SVN--(Eclipse)在历史记录中比较版本差异

    前言 在SVN中比较各版本的差异是非常重要的功能. 方式 看图说话 结果

  3. 行转列(FOR XML PATH)

    SELECT (SELECT ac.ColName+',' FROM T1 AS ac FOR XML PATH('')) AS ColName, (SELECT ac.colTitle+',' FR ...

  4. 2013ACM/ICPC亚洲区南京站现场赛——题目重现

    GPA http://acm.hdu.edu.cn/showproblem.php?pid=4802 签到题,输入两个表,注意细心点就行了. #include<cstdio> #inclu ...

  5. iTunes Connect TERMS OF SERVICE

    iTunes Connect TERMS OF SERVICE THESE TERMS OF SERVICE CONSTITUTE A LEGAL AGREEMENT BETWEEN YOU AND ...

  6. JavaScript原生折叠扩展收缩菜单带缓冲动画

    JavaScript原生折叠扩展收缩菜单带缓冲动画 @落雨 <div id="div_two" style="display: none;"> &l ...

  7. javascript中关于坐标 大小 的描述

    window对象 有效桌面的大小,除去桌面下面的任务栏的高度 window.screen.availHeight : window.screen.availWidth :   浏览器窗口的左上角相对于 ...

  8. NGUI 自定义 Drag Item Script

    最近要实现一个NGUI效果. 查看了一下,NGUI有个自带 UIDragDropItem.cs 的组件进过修改后即可以实现. 下面贴上UI布局,代码: mDragDropItem.cs using U ...

  9. mydate97时间控件最大值最小值限制及Javascript日期判断大小

    <script language="javascript" type="text/javascript" src="<%=basePath ...

  10. POJ 2182

    #include <iostream> #define MAXN 8005 using namespace std; int _m[MAXN]; int main() { //freope ...