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 一堣而安 閱讀(203) 評論(0)  編輯  收藏 所屬分類: java

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 福安市| 交口县| 朝阳县| 许昌县| 祁连县| 贵港市| 麻栗坡县| 凌海市| 永川市| 东兰县| 育儿| 策勒县| 成安县| 周宁县| 松江区| 大同市| 昌吉市| 泸西县| 安乡县| 莒南县| 沾化县| 阿尔山市| 乌海市| 东方市| 定州市| 隆回县| 柳林县| 沂水县| 张掖市| 岳阳县| 佛坪县| 友谊县| 获嘉县| 海丰县| 北辰区| 吉木乃县| 靖江市| 乌兰察布市| 灌阳县| 平原县| 邻水|