private static Properties prop = null;
static {
try {
InputStream inputStream = PropertiesUtil.class.getClassLoader().getResourceAsStream("config.properties"); //讀取配置文件
prop = new Properties();
prop.load(inputStream); //將輸入流寫入prop
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
properties還提供了對應的put方法設置相關屬性
項目中我們直接使用get(key)方法獲得配置文件中的信息.