java讀取配置檔案

2021-08-29 07:18:40 字數 597 閱讀 5524

現今的程式都要求能夠讀寫配置檔案,使得程式的配置資訊能夠很方便地修改。

讀取配置檔案通常使用property檔案,下面列舉了從hadoop的hdfs和本地的檔案系統讀取配置的例子。

話不多說,上**:

//讀取hdfs配置檔案

public static properties getpropertiesfromhdfs(string path) catch (ioexception e2)

inputstreamreader read = null;

try catch (unsupportedencodingexception e1)

try catch (ioexception e)

return prop;

}

下面是從本地讀取:

public static properties getpropertiesfromlocal(string path)  catch (exception e)  finally  catch (ioexception e) }}

return prop;

}

java 讀取配置檔案

前幾天因為配置檔案的事,線上的job掛掉了,使用的是spring載入配置檔案方式。spring配置如下 test.properties api test.properties decryptpropertyplaceholderconfigurer類如下所示。public class decrypt...

java讀取配置檔案property

properties pro new properties try catch filenotfoundexception e catch ioexception e propertynames 返回屬性列表中所有鍵的列舉 enumeration enu2 pro.propertynames whi...

Java讀取Properties配置檔案

properties類繼承自hashtable類並且實現了map介面,使用鍵值對的形式來儲存屬性集。不過properties的鍵和值都是字串型別。1 load inputstream instream 此方法可以從.properties屬性檔案對應的檔案輸入流中,載入屬性列表到properties類...