獲取專案中的檔案方法

2022-02-06 05:52:10 字數 444 閱讀 8705

tomcat環境獲取檔案方法:

string htmlfile = request.getservletcontext().getrealpath("/html/zhantu.html");

下面是我在jersey框架中開發的:

springboot環境獲取resouces下的檔案方法:

resourceutils.getfile("classpath:html").getpath();(html是我在resources下建的資料夾名稱)

下面是在springboot環境springmvc框架中獲取檔案的方法:

獲取專案中的檔案路徑

必須在類路徑src下 目錄中不能有中文和空格 統一的方式,提高 的可移植性 linux和windows都可 getresource 已經定位到 src 目錄,只需要填入該檔案的相對於src的目錄 string path thread.currentthread getcontextclassload...

Java 專案中獲取路徑的方法小計

getclass getresource path path為 開頭時是從classpath下尋找,否則從當前類所在路徑尋找 getclassloader getresource path 從classpath下尋找 getresource path 返回路徑上匹配的第乙個資源 getresourc...

SpringBoot專案中獲取配置檔案的配置資訊

假如我們配置檔案.yaml的資訊是 myconfig username abc password 123或者.properties myconfig.username abc myconfig.password 123類需要被spring掃瞄到 component public class myco...