zoukankan      html  css  js  c++  java
  • getPath

    getPath()与getAbsolutePath()的区别
    public void diff_pathAndAbsolutePath(){
    File file1 = new File(“.	est1.txt”);
    File file2 = new File(“D:workspace	est	est1.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());
    }

    得到的结果:

    —–默认相对路径:取得路径不同——
    . est1.txt
    D:workspace est. est1.txt
    —–默认绝对路径:取得路径相同——
    D:workspace est est1.txt
    D:workspace est est1.txt

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

  • 相关阅读:
    C# Dev PropertyGrid
    C# PropertyGrid控件应用心得
    FileWriter不覆盖
    FileWriter
    java试题
    Java线程池
    java自带线程池和队列详细讲解
    HashMap练习题
    Map集合
    java指定
  • 原文地址:https://www.cnblogs.com/rijiyuelei/p/12376731.html
Copyright © 2011-2022 走看看