久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

Java獲取工程路徑方法詳解

瀏覽:6日期:2022-09-03 15:26:46

第一種:

File f = new File(this.getClass().getResource('/').getPath()); System.out.println(f);

結果:

C:Documents%20and%20SettingsAdministratorworkspaceprojectNamebin  獲取當前類的所在工程路徑;

如果不加“/”:

File f = new File(this.getClass().getResource('').getPath()); System.out.println(f);

結果:

C:Documents%20and%20SettingsAdministratorworkspaceprojectNamebincomtest 獲取當前類的絕對路徑;

第二種

File directory = new File('');//參數為空 String courseFile = directory.getCanonicalPath() ; System.out.println(courseFile);

結果:

C:Documents and SettingsAdministratorworkspaceprojectName 獲取當前類的所在工程路徑;

第三種

URL xmlpath = this.getClass().getClassLoader().getResource('selected.txt'); System.out.println(xmlpath);

結果:

file:/C:/Documents%20and%20Settings/Administrator/workspace/projectName/bin/selected.txt 獲取當前工程src目錄下selected.txt文件的路徑

第四種

System.out.println(System.getProperty('user.dir'));

結果:

C:Documents and SettingsAdministratorworkspaceprojectName

獲取當前工程路徑

第五種

System.out.println( System.getProperty('java.class.path'));

結果:

C:Documents and SettingsAdministratorworkspaceprojectNamebin 獲取當前工程路徑

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Java
相關文章:
主站蜘蛛池模板: 丹巴县| 吉安县| 柳林县| 灯塔市| 玉溪市| 石嘴山市| 鄱阳县| 高陵县| 那坡县| 桐柏县| 土默特右旗| 壤塘县| 荣成市| 松桃| 浦县| 辉南县| 石棉县| 勃利县| 万州区| 乐东| 周口市| 晋宁县| 新营市| 涟水县| 微山县| 武宣县| 麻江县| 安多县| 长治市| 永新县| 巴林左旗| 富裕县| 松阳县| 垦利县| 金湖县| 拉萨市| 西充县| 宜城市| 隆化县| 车致| 从化市|