關於讀取.properties配置文件
阿新 • • 發佈:2018-09-27
clas static end sta public args mage img 技術
【前言】最近筆者,思緒中縈繞著這麽一句話“艾歐尼亞在改變”。因此,筆者就在想。艾歐尼亞的世界在改變,為什麽自己要一成不變的去應對這個變化的艾歐尼亞。找個借口說:“我是雙子座的,我時刻都在改變著”。
一、在src下創建
二、propertites文件內容
三、代碼
package com.css.java.learning.massbag; import java.io.FileInputStream; import java.util.Properties; /** * java讀取propertites配置文件 * @author Red_Ant 20180926 */ public class ReadProperty { public static void redPropertites() { FileInputStream in = null; try { Properties properties = new Properties(); in = new FileInputStream(ReadProperty.class.getResource("20180926.properties").getPath()); properties.load(in); StringBuilder sb = new StringBuilder(); sb.append(properties.getProperty("r")); sb.append(properties.getProperty("e")); sb.append(properties.getProperty("d")); sb.append(properties.getProperty("a")); sb.append(properties.getProperty("n")); sb.append(properties.getProperty("t")); System.out.println("讀取配置信息成功!"); System.err.println(sb); } catch (Exception e) { e.printStackTrace(); System.out.println("讀取配置信息失敗!"); } finally { if (in != null) { try { in.close(); } catch (Exception e) { e.printStackTrace(); } } } } public static void main(String[] args) { redPropertites(); } }
四、操作結果
關於讀取.properties配置文件