這篇文章主要介紹了java簡單讀取properties設定檔的方法,涉及java針對properties配置的載入及檔案屬性讀取相關操作技巧,需要的朋友可以參考下
本文實例講述了java簡單讀取properties設定檔的方法。分享給大家供大家參考,具體如下:
讀取設定文件,小結如下
import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; public class loadConf { private Properties prop = new Properties(); private void loadconf() throws FileNotFoundException, IOException { String path = "com/jlc/util/user.properties"; prop.load(loadConf.class.getClassLoader() .getResourceAsStream(path)); } public loadConf() throws FileNotFoundException, IOException { loadconf(); } public boolean chkProperty(String _key) { return prop.containsKey(_key); } public String getProperty(String _key) { return prop.getProperty(_key); } public static void main(String[] args) throws FileNotFoundException, IOException { loadConf mycnf = new loadConf(); System.out.println(mycnf.chkProperty("address")); System.out.println(mycnf.getProperty("poart")); } }
以上是Java讀取properties設定檔的簡單實例的詳細內容。更多資訊請關注PHP中文網其他相關文章!