載入pro.properties配置檔案
//1.載入(讀取)配置檔案
建立properties物件
properties pro = new properties();
載入配置檔案,轉換為乙個集合(雙列map集合)
.1.獲取class(類)目錄下的配置檔案(即獲取檔案路徑)
//首先通過類的class屬性獲取位元組碼檔案,然後獲取類載入器
//對應的類載入器
classloader cl = demo05reflect_test.class.getclassloader();
//類載入器可以找到類(class)目錄下的class(位元組碼)檔案,也可以找到配置檔案
//類載入器中有個方法getresource(string name)獲取資源的路徑
//還有乙個方法getresourceasstream(string name)直接獲取這個資源對應的位元組流
//pro物件呼叫load()方法載入配置檔案時就需要傳遞位元組流
//properties檔案放置在src檔案下
inputstream is = cl.getresourceasstream("pro.properties");
pro.load(is);//至此以載入完配置檔案
//2.獲取配置檔案中定義的資料
string classname = pro.getproperty("classname");//獲取全類名
string methodname = pro.getproperty("methodname");//獲取方法名
載入配置檔案
1.載入配置檔案 建立properties物件 properties pro newproperties 載入配置檔案,轉為乙個集合 classloader classloader reflecttest.class getclassloader 獲取類載入器 inputstream resourc...
Spring配置檔案載入外部配置檔案
有時,應用程式可能需要從不同的位置 例如 檔案系統 classpath或者url 讀取外部資源 例如 文字檔案 xml檔案 屬性檔案或或者影象檔案 通常,為了從不同位置載入資源,需要和不同的api打交道。spring的資源載入器提供了乙個統一的getresource 方法,使用這個方法可以通過資源路...
struts2配置檔案載入順序
struts2框架要能執行,必須先載入strutsprepareandexecutefilter.在strutsprepareandexecutefilter的init方法中對dispatcher進行了初始化.在dispatcher類中定義的init方法內就描述了struts2配置檔案載入的順序 在...