日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

java獲取路徑【轉載】

 小傅哥 2021-12-13
package my;

 import java.io.File;
 import java.io.IOException;
 import java.net.URL;

 public class MyUrlDemo {

     
     public static void main(String[] args) {
         MyUrlDemo muDemo = new MyUrlDemo();
         try {
             muDemo.showURL();
         } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }

     public void showURL() throws IOException {

         // 第一種:獲取類加載的根路徑   D:\git\daotie\daotie\target\classes
         File f = new File(this.getClass().getResource("/").getPath());
         System.out.println(f);

         // 獲取當前類的所在工程路徑; 如果不加“/”  獲取當前類的加載目錄  D:\git\daotie\daotie\target\classes\my
         File f2 = new File(this.getClass().getResource("").getPath());
         System.out.println(f2);

         // 第二種:獲取項目路徑    D:\git\daotie\daotie
         File directory = new File("");// 參數(shù)為空
         String courseFile = directory.getCanonicalPath();
         System.out.println(courseFile);

 
         // 第三種:  file:/D:/git/daotie/daotie/target/classes/
         URL xmlpath = this.getClass().getClassLoader().getResource("");
         System.out.println(xmlpath);

 
         // 第四種: D:\git\daotie\daotie
         System.out.println(System.getProperty("user.dir"));
         /*
          * 結果: C:\Documents and Settings\Administrator\workspace\projectName
          * 獲取當前工程路徑
          */

         // 第五種:  獲取所有的類路徑 包括jar包的路徑
         System.out.println(System.getProperty("java.class.path"));

     }
 }

    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多