日韩精品欧美激情国产一区_中文无码精品一区二区三区在线_岛国毛片AV在线无码不卡_亞洲歐美日韓精品在線_使劲操好爽好粗视频在线播放_日韩一区欧美二区_八戒八戒网影院在线观看神马_亚洲怡红院在线色网_av无码不卡亚洲电影_国产麻豆媒体MDX

java獲取指定資源文件路徑的幾種方法

時間:2020-01-29 21:14:48 類型:JAVA
字號:    

指定資源路徑的方法有兩種:

一種是絕對路徑,一種是相對路徑。

獲取當前類的所在工程路徑; 
File f = new File(this.getClass().getResource("/").getPath()); 
System.out.println(f); 
獲取當前類的絕對路徑; 
File f = new File(this.getClass().getResource("").getPath()); 
System.out.println(f); 
獲取當前類的所在工程路徑; 
File directory = new File("");//參數(shù)為空 
String courseFile = directory.getCanonicalPath() ; 
System.out.println(courseFile); 
獲取當前工程src目錄下selected.txt文件的路徑:
URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt"); 
System.out.println(xmlpath);


<