tinguo002

           

          java獲取路徑

          String catalinaHome = new File("").getAbsolutePath();


          getAbsolutePath() 得到絕對路徑、全路徑。
          getpath 得到縮寫的路徑,根據當前目錄位置可以縮寫路徑。得到相對路徑。
          getCanonicalPath() 得到標準路徑,將統一平臺間的路徑寫法差異。
          package util;

          import java.io.File;

          public class CurrentDirectory {
              
              
          public static void print(Object o) {
                  System.out.println(o);
              }


              
          public static void main(String[] args) throws Exception {
                  print(Thread.currentThread().getContextClassLoader().getResource(
          ""));
                  print(CurrentDirectory.
          class.getClassLoader().getResource(""));
                  
          //print(this.getClass().getResource("/").toString().replace("file:/", "")); //在非靜態方法中可以使用
                  print(ClassLoader.getSystemResource(""));
                  print(CurrentDirectory.
          class.getResource(""));
                  print(CurrentDirectory.
          class.getResource("/"));
                  print(
          new File("").getAbsolutePath());
                  print(System.getProperty(
          "user.dir"));
              }

              
          }




          歡迎大家訪問我的個人網站 萌萌的IT人

          posted on 2014-02-24 10:43 一堣而安 閱讀(197) 評論(0)  編輯  收藏 所屬分類: java

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 盐津县| 林口县| 顺昌县| 泰宁县| 张家港市| 满洲里市| 平陆县| 丹巴县| 鹰潭市| 罗甸县| 托克逊县| 孝感市| 茂名市| 平塘县| 澎湖县| 浙江省| 延吉市| 宝兴县| 普定县| 米易县| 宁明县| 南雄市| 江川县| 祁阳县| 惠州市| 武宁县| 包头市| 宁晋县| 会理县| 鱼台县| 木兰县| 大足县| 乐清市| 宕昌县| 钟山县| 贡嘎县| 板桥市| 霍邱县| 商城县| 壤塘县| 亚东县|