java獲取當前專案及類的路徑方法 阿新 • • 發佈:2019-01-11 File f1 = new File(this.getClass().getResource("/").getPath()); System.out.println("獲取當前類的所在工程路徑"+f1); File f2 = new File(this.getClass().getResource("").getPath()); System.out.println("獲取當前類的絕對路徑"+f2); File directory = new File("");//引數為空 String courseFile = null; try { courseFile = directory.getCanonicalPath(); } catch (IOException e) { e.printStackTrace(); } System.out.println("獲取當前類的所在工程路徑"+courseFile); URL xmlpath = new AccountManageController().getClass().getClassLoader().getResource("privateKey"); System.out.println("獲取當前工程src目錄下privateKey檔案的路徑 "+xmlpath); System.out.println("獲取當前工程路徑 "+System.getProperty("user.dir")); System.out.println("獲取當前工程所有jar包路徑 "+System.getProperty("java.class.path"));