java讀取properties檔案內容
阿新 • • 發佈:2019-01-26
public class LoadProperties { private static LoadProperties sington=null; private static Properties properties=null; private LoadProperties(String configFile){ properties=new Properties(); try { properties.load(UserRegist.class.getClassLoader().getResourceAsStream(configFile)); } catch (IOException e) { e.printStackTrace(); } } // configFile:properties檔案全名。例:my.properties public static LoadProperties getSington(String configFile) { if(sington==null){ sington=new LoadProperties(configFile); } return sington; } // 獲得name對應的值 public String getValue(String name){ return properties.getProperty(name).trim(); } }