1. 程式人生 > >Web專案獲取專案“相對路徑”,以獲取特定資源

Web專案獲取專案“相對路徑”,以獲取特定資源

//類載入根路徑
String classPath = this.getClass().getResource("/").getPath();

//類載入根路徑
URL xmlPath = this.getClass().getClassLoader().getResource("");

//類所在工程根路徑
String proClassPath = this.getClass().getResource("").getPath();

//專案伺服器指令碼檔案路徑
File directory = new File("");// 引數為空
String proRootPath = directory.getCanonicalPath();

//專案伺服器指令碼檔案路徑
String proPath = System.getProperty(“user.dir”);

// 獲取所有的類路徑 包括jar包的路徑
String allClassPath = System.getProperty(“java.class.path”);

//專案部署的路徑
String path = request.getSession().getServletContext().getRealPath("/");