国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

Java獲取文件路徑的幾種方法

2019-11-06 07:08:27
字體:
來源:轉載
供稿:網(wǎng)友
第一種: File f = new File(this.getClass().getResource("/").getPath()); System.out.PRintln(f); 結果: C:/Documents%20and%20Settings/Administrator/workspace/projectName/bin 獲取當前類的所在工程路徑; 如果不加“/” File f = new File(this.getClass().getResource("").getPath()); System.out.println(f); 結果: C:/Documents%20and%20Settings/Administrator/workspace/projectName/bin/com/test 獲取當前類的絕對路徑; 第二種: File directory = new File("");//參數(shù)為空 String courseFile = directory.getCanonicalPath() ; System.out.println(courseFile); 結果: C:/Documents and Settings/Administrator/workspace/projectName 獲取當前類的所在工程路徑; 第三種: 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 Settings/Administrator/workspace/projectName 獲取當前工程路徑 第五種: System.out.println( System.getProperty("java.class.path")); 結果: C:/Documents and Settings/Administrator/workspace/projectName/bin 獲取當前工程路徑
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 芷江| 通榆县| 遵化市| 阳朔县| 肥西县| 清镇市| 容城县| 塔河县| 京山县| 海淀区| 图木舒克市| 永定县| 和顺县| 贡山| 水城县| 梁山县| 化德县| 同德县| 苍山县| 兴义市| 西青区| 广州市| 桃园县| 涡阳县| 会东县| 长治县| 鹤壁市| 拉萨市| 保德县| 珠海市| 晋宁县| 元朗区| 昌宁县| 五指山市| 安吉县| 增城市| 晋城| 安宁市| 新沂市| 阳高县| 沾化县|