国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

Java獲取工程路徑方法詳解

瀏覽:7日期: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
相關文章:
主站蜘蛛池模板: 永春县| 岑巩县| 嘉荫县| 桦甸市| 阿拉善右旗| 太仆寺旗| 贺兰县| 会昌县| 唐海县| 兴业县| 娱乐| 屯昌县| 嘉荫县| 平原县| 紫云| 察雅县| 和平县| 阿瓦提县| 自贡市| 双辽市| 会泽县| 荆州市| 孟津县| 通江县| 禄丰县| 寿光市| 郁南县| 阳山县| 平阴县| 五台县| 兴安盟| 呼伦贝尔市| 黄骅市| 电白县| 亚东县| 芒康县| 翼城县| 赫章县| 东台市| 治县。| 余江县|